使用Cucumber的Hyperledger作曲家单元测试。类型错误: 无法读取 null 的属性'getClassDeclaration'



我正在使用Cucumber在Hyperledger作曲家上运行一些单元测试。我经常收到此类型错误:无法读取空的属性"getClassDeclaration">

资产代码为

asset Clicks identified by id {
o String id
o String ipAddress
o String publisherId
o String advertiserId
o String CreatedAt
}

交易代码为

transaction Clicks_Add 
{
o Clicks clicks
}

.JS文件中事务的代码

/**
* transaction
* @param {org.adverce.Clicks_Add} Clicks_Add
* @transaction
* This transaction is used to add new users to an already created Advertiser.
*/
function Clicks_Add(newClick) {
var factory = getFactory();
var NS='org.adverce';
var clicks = factory.newResource(NS,'Clicks',newClick.clicks.id);
clicks.ipAddress = newClick.clicks.ipAddress;
clicks.publisherId = newClick.clicks.publisherId;
clicks.advertiserId = newClick.clicks.advertiserId;
clicks.CreatedAt = newClick.clicks.CreatedAt;
return getAssetRegistry('org.adverce.Clicks')
.then(function(newclicks){
newclicks.addAll([clicks]);
})
}

现在我写的黄瓜测试是这样的。

Feature: Want to test the Clicks transactions
Scenario: Clicks Transaction send value to Clicks Assets
Given I have deployed my network
When I submit the following transaction of type org.adverce.Clicks_Add
| id | ipAddress   | publisherId | advertiserId | CreatedAt |
| 01 | 192.168.1.1 | 12          | 22           | 27/1/2017 |
Then I should have the following Assets
"""
[
{"$class":"org.adverce.Clicks", "id":"01", "ipAddress":"192.168.1.1", "publisherId":"23", "advertiserId":"22", "CreatedAt":"27,1,2017"}
]
"""

为这些测试编写的方法如下:

'use strict';

module.exports = function () {
this.Given('I have deployed my network', function () {  
// Write code here that turns the phrase above into concrete actions
});
this.When(/^I submit the following transactions? of type ([.w]+).(w+)$/, function (namespace, name, table) {
return this.composer.submitTransactions(namespace, name, table);
});
this.Then(/^I should have the following Assets?$/, function (docString) {
return this.composer.testAssets(null, null, docString);
}); 
};

我也会在这里分享错误截图。

运行测试后终端中的错误输出

我认为它失败的主要原因是因为您没有定义如何正确部署网络 - 如您所知,Composer 无论如何都会为您设置这个,如果您查看 Composer 示例网络示例(例如基本示例网络(https://github.com/hyperledger/composer-sample-networks/blob/master/packages/basic-sample-network/features/support/index.js

作为参考,"基本样本网络"中的样本黄瓜测试(包括添加资产(在这里 -> https://github.com/hyperledger/composer/blob/master/packages/composer-cucumber-steps/test/composer.js#L73 和

最后提交交易的示例(另一个示例网络(在这里 -> https://github.com/hyperledger/composer-sample-networks/blob/master/packages/fund-clearing-network/features/1.SubmitTransferRequests.feature

最新更新