提交 2fae914a 编写于 作者: 杜庆泉's avatar 杜庆泉

增加console.log 自动化测试代码

上级 0cfffe72
<template>
<button @click="logStr">打印字符串</button>
<button @click="logFloat">打印浮点数</button>
<button @click="logInt">打印整数</button>
<button @click="logObject">打印对象</button>
<button @click="logFunction">打印函数</button>
<div>
<button @click="doLogTest">打印测试</button>
<text>{{testRet}}</text>
</div>
</template>
<script>
import {
logStrTest,
logIntTest,
logFloatTest,
logObjectTest,
logFunctionTest
} from '@/uni_modules/uts-advance'
import { getLog,logObjectTest,logClassTest,logFunctionTest,logFileTest,logDateTest } from '../../uni_modules/uts-api-test'
export default {
data() {
return {}
return {
testRet:''
}
},
methods: {
logStr() {
logStrTest()
},
logFloat() {
logFloatTest()
},
logInt() {
logIntTest()
},
logObject() {
logObjectTest()
},
logFunction() {
logFunctionTest()
},
doLogTest() {
if(getLog("") != '{"type":"string","value":""}'){
this.testRet = "测试失败"
return;
}
if(getLog("字符串打印测试") != '{"type":"string","value":"字符串打印测试"}'){
this.testRet = "测试失败"
return;
}
if(getLog(2023) != '{"type":"number","value":"2023"}'){
this.testRet = "测试失败"
return;
}
// console.log(getLog(2023.0))
// if(getLog(2023.0) != '{"type":"number","value":"2023"}'){
// this.testRet = "测试失败"
// return;
// }
if(getLog(2023.002) != '{"type":"number","value":"2023.002"}'){
this.testRet = "测试失败"
return;
}
if(logObjectTest() != '{"className":"uts.sdk.modules.utsApiTest.ParamOptions","subType":"object","__$originalPosition":"","type":"object","value":{"methods":[],"properties":[{"name":"array","subType":"array","className":"io.dcloud.uts.UTSArray","type":"object","value":{"properties":[{"name":0,"type":"string","value":"1"},{"name":1,"type":"string","value":"2"},{"name":2,"type":"string","value":"3"}]}},{"name":"title","type":"string","value":"logObjectTest"}]}}'){
this.testRet = "测试失败"
return;
}
if(logFunctionTest() != '{"parameter":[],"type":"function"}'){
this.testRet = "测试失败"
return;
}
if(logClassTest() != '{"className":"uts.sdk.modules.utsApiTest.C","subType":"object","__$originalPosition":"","type":"object","value":{"methods":[],"properties":[{"name":"name","type":"string","value":"ccc"},{"parameter":["string"],"name":"sayBye","type":"function"}]}}'){
this.testRet = "测试失败"
return;
}
/**
* uvue 和 vue 因为 java 版本不同,所以这里的打印格式可能存在差异
*/
if(logFileTest() != '{"className":"java.io.File","subType":"object","type":"object","value":{"methods":[],"properties":[]}}'){
this.testRet = "测试失败"
return;
}
if(logDateTest() != '{"className":"io.dcloud.uts.Date","subType":"date","type":"object","value":"Sat Aug 08 1998 08:00:00 GMT+0800"}'){
this.testRet = "测试失败"
return;
}
this.testRet = "测试完成"
}
}
}
......
<template>
<div>
<button @click="logStr">打印字符串</button>
<button @click="logFloat">打印浮点数</button>
<button @click="logInt">打印整数</button>
<button @click="logObject">打印对象</button>
<button @click="logFunction">打印函数</button>
<button @click="logFile">打印文件</button>
<button @click="logDate">打印日期</button>
<button @click="logDateCombine">组合打印日期</button>
<button @click="doLogTest">打印测试</button>
<text>{{testRet}}</text>
</div>
</template>
<script>
import {
logStrTest,
logIntTest,
logFloatTest,
logObjectTest,
logFunctionTest,
logDateTest,
logFileTest,
logDateCombineTest
} from '@/uni_modules/uts-advance'
import { getLog,logObjectTest,logClassTest,logFunctionTest,logFileTest,logDateTest } from '../../uni_modules/uts-api-test'
export default {
data() {
return {}
return {
testRet:''
}
},
methods: {
logStr() {
logStrTest()
},
logFloat() {
logFloatTest()
},
logInt() {
logIntTest()
},
logObject() {
logObjectTest()
},
logFunction() {
logFunctionTest()
},
logFile() {
logFileTest()
},
logDate() {
logDateTest()
},
logDateCombine() {
logDateCombineTest()
},
doLogTest() {
if(getLog("") != '{"type":"string","value":""}'){
this.testRet = "测试失败"
return;
}
if(getLog("字符串打印测试") != '{"type":"string","value":"字符串打印测试"}'){
this.testRet = "测试失败"
return;
}
if(getLog(2023) != '{"type":"number","value":"2023"}'){
this.testRet = "测试失败"
return;
}
if(getLog(2023.0) != '{"type":"number","value":"2023"}'){
this.testRet = "测试失败"
return;
}
if(getLog(2023.002) != '{"type":"number","value":"2023.002"}'){
this.testRet = "测试失败"
return;
}
if(logObjectTest() != '{"className":"uts.sdk.modules.utsApiTest.ParamOptions","subType":"object","__$originalPosition":"","type":"object","value":{"methods":[],"properties":[{"name":"array","subType":"array","className":"io.dcloud.uts.UTSArray","type":"object","value":{"properties":[{"name":0,"type":"string","value":"1"},{"name":1,"type":"string","value":"2"},{"name":2,"type":"string","value":"3"}]}},{"name":"title","type":"string","value":"logObjectTest"}]}}'){
this.testRet = "测试失败"
return;
}
if(logFunctionTest() != '{"parameter":[],"type":"function"}'){
this.testRet = "测试失败"
return;
}
if(logClassTest() != '{"className":"uts.sdk.modules.utsApiTest.C","subType":"object","__$originalPosition":"","type":"object","value":{"methods":[],"properties":[{"name":"name","type":"string","value":"ccc"},{"parameter":["string"],"name":"sayBye","type":"function"}]}}'){
this.testRet = "测试失败"
return;
}
if(logFileTest() != '{"className":"java.io.File","subType":"object","type":"object","value":{"methods":[],"properties":[{"name":"filePath","type":"null","value":"null"},{"name":"path","type":"string","value":"/sdcard/temp/1.txt"},{"name":"prefixLength","subType":"number","type":"Int","value":"1"},{"name":"status","type":"null","value":"null"}]}}'){
this.testRet = "测试失败"
return;
}
if(logDateTest() != '{"className":"io.dcloud.uts.Date","subType":"date","type":"object","value":"Sat Aug 08 1998 08:00:00 GMT+0800"}'){
this.testRet = "测试失败"
return;
}
this.testRet = "测试完成"
}
}
}
......
......@@ -433,53 +433,6 @@ export function callbackParam(callback : ParamCallback) {
}
callback(ret)
}
/**
* 打印测试方法
*/
export function logStrTest() {
console.log("logStrTest 字符串打印测试")
}
export function logFloatTest() {
console.log(3.1415926)
}
export function logIntTest() {
console.log(2023)
console.log(2023.0)
console.log(2023.002)
}
export function logObjectTest(){
let ret : ParamOptions = {
title: "logObjectTest",
array: ['1', '2', '3']
}
console.log(ret)
}
export function logFunctionTest(){
let testFun = function(){
console.log("testFun")
}
console.log(testFun)
}
export function logFileTest(){
console.log(new File("/sdcard/temp/1.txt"))
}
export function logDateTest(){
console.log(new Date())
}
export function logDateCombineTest(){
console.log("现在的日期是",new Date()," 以上是日期信息")
}
/**
......
{
"id": "uts-test",
"displayName": "uts-test",
"version": "1.0.0",
"description": "uts-test",
"keywords": [
"uts-test"
],
"repository": "",
"engines": {
"HBuilderX": "^3.6.8"
},
"dcloudext": {
"type": "uts",
"sale": {
"regular": {
"price": "0.00"
},
"sourcecode": {
"price": "0.00"
}
},
"contact": {
"qq": ""
},
"declaration": {
"ads": "",
"data": "",
"permissions": ""
},
"npmurl": ""
},
"uni_modules": {
"dependencies": [],
"encrypt": [],
"platforms": {
"cloud": {
"tcb": "u",
"aliyun": "u",
"alipay": "u"
},
"client": {
"Vue": {
"vue2": "u",
"vue3": "u"
},
"App": {
"app-android": "u",
"app-ios": "u"
},
"H5-mobile": {
"Safari": "u",
"Android Browser": "u",
"微信浏览器(Android)": "u",
"QQ浏览器(Android)": "u"
},
"H5-pc": {
"Chrome": "u",
"IE": "u",
"Edge": "u",
"Firefox": "u",
"Safari": "u"
},
"小程序": {
"微信": "u",
"阿里": "u",
"百度": "u",
"字节跳动": "u",
"QQ": "u",
"钉钉": "u",
"快手": "u",
"飞书": "u",
"京东": "u"
},
"快应用": {
"华为": "u",
"联盟": "u"
}
}
}
}
}
\ No newline at end of file
# uts-test
### 开发文档
[UTS 语法](https://uniapp.dcloud.net.cn/tutorial/syntax-uts.html)
[UTS API插件](https://uniapp.dcloud.net.cn/plugin/uts-plugin.html)
[UTS 组件插件](https://uniapp.dcloud.net.cn/plugin/uts-component.html)
[Hello UTS](https://gitcode.net/dcloud/hello-uts)
\ No newline at end of file
{
"minSdkVersion": "21"
}
\ No newline at end of file
/* 引入 interface.uts 文件中定义的变量 */
import { GetLog } from '../interface.uts';
import File from 'java.io.File';
export const getLog : GetLog = function (param : Any|null) : string {
let allLog = console.getLogV2(param);
/**
* 移除掉干扰因素,仅返回打印对象本身的序列化结果
*/
if(!allLog.startsWith("---BEGIN:CONSOLE---")){
return ""
}
if(!allLog.endsWith("---END:CONSOLE---")){
return ""
}
let jsonLog = allLog
jsonLog = jsonLog.replace("---BEGIN:CONSOLE---", "")
jsonLog = jsonLog.replace("---END:CONSOLE---", "")
let jsonArrayObj = JSON.parse<UTSArray<UTSJSONObject>>(jsonLog)
return jsonArrayObj![0].toJSONString()
}
type ParamOptions = {
title : string,
array : Array<string>
}
class C {
name:string = "default"
sayBye = function(word:string){
console.log("sayBye",word)
}
sayHello(word:string){
console.log("sayHello",word)
}
}
export function logObjectTest():string{
let ret : ParamOptions = {
title: "logObjectTest",
array: ['1', '2', '3']
}
let typeLogRet = getLog(ret)
let typeLogObj = JSON.parseObject(typeLogRet)!
let typeLogObjPos = typeLogObj.getJSON("__$originalPosition")!
if("ParamOptions" != typeLogObjPos['name']){
return ""
}
/**
* 编译出来的位置信息可能有差异,排除单独验证后,排除掉这个字段
*/
typeLogObj.set("__$originalPosition","")
return typeLogObj.toJSONString()
}
export function logFunctionTest():string{
let testFun = function(){
console.log("testFun")
}
return getLog(testFun)
}
export function logFileTest():string{
return getLog(new File("/sdcard/temp/1.txt"))
}
export function logDateTest():string{
return getLog(new Date('1998-08-08'))
}
export function logClassTest():string{
let c = new C()
c.name="ccc"
let classLogRet = getLog(c)
let classLogObj = JSON.parseObject(classLogRet)!
let classLogObjPos = classLogObj.getJSON("__$originalPosition")!
if("C" != classLogObjPos['name']){
return ""
}
/**
* 编译出来的位置信息可能有差异,排除单独验证后,排除掉这个字段
*/
classLogObj.set("__$originalPosition","")
return classLogObj.toJSONString()
}
/* 同步函数定义 */
export type GetLog = (logObject : Any|null) => string
\ No newline at end of file
/* 此规范为 uni 规范,可以按照自己的需要选择是否实现 */
/**
* 错误主题
* 注意:错误主题一般为插件名称,每个组件不同,需要使用时请更改。
* [可选实现]
*/
export const UniErrorSubject = 'uts-test';
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册