request-TDD

Signed-off-by: renjiecui <cuirenjie@huawei.com>
This commit is contained in:
renjiecui 2022-08-30 16:24:52 +08:00
parent 4887c289ab
commit c56144c505
6 changed files with 175 additions and 0 deletions

View File

@ -22,6 +22,7 @@ group("request_packages") {
"download/interfaces/kits/js/napi/download_single:downloadsingle",
"download/sa_profile:download_sa_profiles",
"download/services:download_server",
"test/unittest/common:unittest",
]
}
}

View File

@ -79,6 +79,7 @@
"//base/request/request/upload/unitest:upload_obtain_file_UT_test",
"//base/request/request/upload/unitest:upload_UT_test",
"//base/request/request/test/fuzztest:fuzztest"
"//base/request/request/test/unittest/common:unittest"
]
}
}

View File

@ -0,0 +1,30 @@
# Copyright (C) 2022 Huawei Device Co., Ltd.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import("//build/test.gni")
module_output_path = "request/napi"
ohos_js_unittest("RequestJsTest") {
module_out_path = module_output_path
hap_profile = "./config.json"
# certificate_profile = "//test/developertest/signature/openharmony_sx.p7b"
certificate_profile = "./openharmony_sx.p7b"
}
group("unittest") {
testonly = true
deps = [ ":RequestJsTest" ]
}

View File

@ -0,0 +1,62 @@
/*
* Copyright (C) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from 'deccjsunit/index';
import request from '@ohos.request';
const TAG = "REQUEST_TEST";
let keyStr = 'download test ';
let DownloadConfig = {
//https://sf3-cn.feishucdn.com/obj/ee-appcenter/6d6bc5/Feishu-win32_ia32-5.10.6-signed.exe
// url: 'https://sf3-cn.feishucdn.com/obj/ee-appcenter/6d6bc5/Feishu-win32_ia32-5.10.6-signed.exe', // Resource address.
//url: 'https://www.baidu.com/img/PCtm_d9c8750bed0b3c7d089fa7d55720d6cf.png', // Resource address.
url: 'http://192.168.8.128:8080/HFS_SERVER/123.rar',
// url: 'http://sf3-cn.feishucdn.com/obj/ee-appcenter/6d6bc5/Feishu-win32_ia32-5.10.6-signed.exe',
filePath: '/data/storage/el2/base/haps/entry/files/123.rar', // Sets the path for downloads./data/accounts/account_0/appdata/com.example.downloaddemo/files/picture.png
enableMetered: false,
enableRoaming: false,
networkType: 65536, //65536 wifi 1 sim卡网络
background: true,
}
describe('requestTest',function () {
console.log(TAG + "*************Unit Test Begin*************");
/**
* @tc.name: downloadTest001
* @tc.desc see if download starts correctly
* @tc.type: FUNC
* @tc.require:
*/
it('downloadTest001', 0, function () {
console.log(TAG + "************* downloadTest001 start *************");
request.download(DownloadConfig).then((DownloadTask) => {
console.log(keyStr + 'download start, DownloadTask: ' + DownloadTask);
console.log(keyStr + 'download start, DownloadTask: ' + JSON.stringify(DownloadTask));
DownloadTask.on('progress',(receivedSize, totalSize) => {
expect(totalSize == 0).assertEqual(false)
expect(receivedSize == 0).assertEqual(false);
})
})
console.log(TAG + "************* downloadTest001 end *************");
})
console.log(TAG + "*************Unit Test End*************");
})

View File

@ -0,0 +1,81 @@
{
"app": {
"bundleName": "com.example.myapplication",
"vendor": "example",
"version": {
"code": 1,
"name": "1.0"
},
"apiVersion": {
"compatible": 4,
"target": 5
}
},
"deviceConfig": {},
"module": {
"package": "com.example.myapplication",
"name": ".MyApplication",
"deviceType": [
"phone"
],
"distro": {
"deliveryWithInstall": true,
"moduleName": "entry",
"moduleType": "entry"
},
"defPermissions": [
{
"availableScope": [],
"grantMode": "user_grant",
"name": "ohos.permission.DISTRIBUTED_DATASYNC"
}
],
"reqPermissions": [
{
"name": "ohos.permission.GRANT_SENSITIVE_PERMISSIONS",
"reason": "ceshi"
},
{
"name": "ohos.permission.DISTRIBUTED_DATASYNC",
"reason": "ceshi"
},
{
"name": "ohos.permission.INTERNET",
"reason": "ceshi"
}
],
"abilities": [
{
"visible": true,
"skills": [
{
"entities": [
"entity.system.home"
],
"actions": [
"action.system.home"
]
}
],
"name": "com.example.myapplication.MainAbility",
"icon": "$media:icon",
"description": "$string:mainability_description",
"label": "MyApplication",
"type": "page",
"launchType": "standard"
}
],
"js": [
{
"pages": [
"pages/index/index"
],
"name": "default",
"window": {
"designWidth": 720,
"autoDesignWidth": false
}
}
]
}
}

Binary file not shown.