对于我的API测试,我的代码以不同的方式表现。我将Jasmine框架与节点js一起使用。我的GET请求将给出2个响应
在第一种情况下,我的测试用例代码如下
private PendingIntent getGeofencePendingIntent() {
// Reuse the PendingIntent if we already have it.
if (mGeofencePendingIntent != null) {
return mGeofencePendingIntent;
}
Intent intent = new Intent(this, GeofenceTransitionsIntentService.class);
// We use FLAG_UPDATE_CURRENT so that we get the same pending intent back when
// calling addGeofences() and removeGeofences().
mGeofencePendingIntent = PendingIntent.getService(this, 0, intent, PendingIntent.
FLAG_UPDATE_CURRENT);
return mGeofencePendingIntent;
}
第二种情况下的代码与上面的相同。但是在我的第一种情况下,我得到的是合格的规格,在第二种情况下,我得到了以下的故障
describe('Verification of BS_004_addressCheck',()=>{
it('Verify success response for BS_004_addressCheck',function(done){
var path=require('path');
let endpoint=require(path.resolve('./config/endpoint_BS_004.json'));
// let pincodes=require(path.resolve('./config/pincodes.json'));
//let request=require(path.resolve('./config/postPin.json'));
//console.log(request.id,request.Name);
const fetch=require('node-fetch');
let baseUrl=endpoint.url;
let apikey=endpoint.apikey;
let country=endpoint.country;
let postcode=endpoint.postcode;
let picklistcount=endpoint.picklistcount;
let uniqueAddressReference=endpoint.uniqueAddressReference;
let fullUrlWithQueryParameters= baseUrl + "?apikey=" + apikey + "&country=" + country + "&postcode=" + postcode + "&picklistcount=" + picklistcount + "&uniqueAddressReference=" + uniqueAddressReference
//let pinCode=pincodes.Vlcy;
console.log(fullUrlWithQueryParameters);
console.log("test");
getR(fullUrlWithQueryParameters)
.then(jsonRes=>{
console.log(jsonRes);
expect(jsonRes).not.toBeUndefined();
expect(jsonRes.Header.ActivityStatusEnum).toBe('SUCCESS');
})
.then(done)
})
})
我的成功响应将花费近400毫秒,但我的失败响应将花费近10000毫秒。所以我猜了一下,并添加了茉莉花超时,如下所示(请参见上面的代码块)
1) Verification of BS_004_addressCheck Verify success response for BS_004_addressCheck
Message:
Error: Timeout - Async callback was not invoked within timeout specified by jasmine.DEFAULT_TIMEOUT_INTERVAL.
Stack:
Error: Timeout - Async callback was not invoked within timeout specified by jasmine.DEFAULT_TIMEOUT_INTERVAL.
at <Jasmine>
at ontimeout (timers.js:498:11)
at tryOnTimeout (timers.js:323:5)
at Timer.listOnTimeout (timers.js:290:5)
1 spec, 1 failure
Finished in 5.012 seconds
Randomized with seed 21049 (jasmine --random=true --seed=21049)
但是现在我有2个错误。
describe('Verification of BS_004_addressCheck',()=>{
beforeAll(function(done) {
jasmine.DEFAULT_TIMEOUT_INTERVAL= 10000;
});
//jasmine.DEFAULT_TIMEOUT_INTERVAL= 10000;
it('Verify success response for BS_004_addressCheck',function(done){
var path=require('path');
let endpoint=require(path.resolve('./config/endpoint_BS_004.json'));
// let pincodes=require(path.resolve('./config/pincodes.json'));
//let request=require(path.resolve('./config/postPin.json'));
//console.log(request.id,request.Name);
const fetch=require('node-fetch');
let baseUrl=endpoint.url;
let apikey=endpoint.apikey;
let country=endpoint.country;
let postcode=endpoint.postcode;
let picklistcount=endpoint.picklistcount;
let uniqueAddressReference=endpoint.uniqueAddressReference;
let fullUrlWithQueryParameters= baseUrl + "?apikey=" + apikey + "&country=" + country + "&postcode=" + postcode + "&picklistcount=" + picklistcount + "&uniqueAddressReference=" + uniqueAddressReference
//let pinCode=pincodes.Vlcy;
console.log(fullUrlWithQueryParameters);
console.log("test");
getR(fullUrlWithQueryParameters)
.then(jsonRes=>{
console.log(jsonRes);
expect(jsonRes).not.toBeUndefined();
expect(jsonRes.Header.ActivityStatusEnum).toBe('SUCCESS');
})
.then(done)
})
})
我不确定如何解决此问题。请有人帮我。下面我调用的getR函数
Failures:
1) Verification of BS_004_addressCheck Verify success response for BS_004_addressCheck
Message:
Error: Timeout - Async callback was not invoked within timeout specified by jasmine.DEFAULT_TIMEOUT_INTERVAL.
Stack:
Error: Timeout - Async callback was not invoked within timeout specified by jasmine.DEFAULT_TIMEOUT_INTERVAL.
at <Jasmine>
at ontimeout (timers.js:498:11)
at tryOnTimeout (timers.js:323:5)
at Timer.listOnTimeout (timers.js:290:5)
Suite error: Verification of BS_004_addressCheck
Message:
Error: Timeout - Async callback was not invoked within timeout specified by jasmine.DEFAULT_TIMEOUT_INTERVAL.
Stack:
Error: Timeout - Async callback was not invoked within timeout specified by jasmine.DEFAULT_TIMEOUT_INTERVAL.
at <Jasmine>
at ontimeout (timers.js:498:11)
at tryOnTimeout (timers.js:323:5)
at Timer.listOnTimeout (timers.js:290:5)
1 spec, 2 failures
Finished in 15.015 seconds
Randomized with seed 21999 (jasmine --random=true --seed=21999).
我认为问题是由于响应时间长。但是不知道该如何解决。请告知。
答案 0 :(得分:0)
问题在于,在您的beforeAll
函数回调中,您正在传递done
参数,但是它从未被调用,只需删除它即可。
beforeAll(function() {
jasmine.DEFAULT_TIMEOUT_INTERVAL= 10000;
});
希望有帮助