我想以BDD风格编写Jasmine End 2 End Tests。从我所学到的,这意味着,我有4个方面:
从我天真的看法,我将创建一个测试“个人详细信息”功能,如下所示:
// Feature
describe('Showing Individual Details', () => {
let individualDetailsPage: IndividualDetailsPage;
beforeEach(() => {
individualDetailsPage = new IndividualDetailsPage();
});
// Scenario - New Individual
describe('Given a new Individual', () => {
beforeEach(async () => {
await individualDetailsPage.navigateToDetails('-1');
});
// Incoming Event
describe('When the Details are loaded', () => {
// Ensure outcome
it('Then all Controls are empty', async () => {
expect(individualDetailsPage.firstNameInput.text).toBe('');
expect(individualDetailsPage.lastNameInput.text).toBe('');
expect(individualDetailsPage.birthdateInput.text).toBe('');
});
// Ensure outcome
it('Then the save button is disabled', () => {
expect(individualDetailsPage.saveButton.isEnabled).toBe(false);
});
});
});
});
因此,对于“个人详细信息”功能,如果设置了新的“个人”,则“控件”应为空并且禁用“保存”按钮。从一个天真的角度来看,这似乎还不错。还运行测试,我看到:
这似乎没问题。现在有趣的部分:我想将此更改发布到Azure DevOps,因此我在量角器配置中使用以下代码:
onPrepare() {
require('ts-node').register({
project: require('path').join(__dirname, './tsconfig.e2e.json')
});
var jasmineReporters = require('jasmine-reporters');
var junitReporter = new jasmineReporters.JUnitXmlReporter({
savePath: 'testresults',
filePrefix: 'e2e-tests',
consolidateAll: true
});
jasmine.getEnv().addReporter(junitReporter);
}
不幸的是,XML看起来像这样:
<testsuite name="Showing Individual Details" timestamp="2019-02-04T18:23:33" hostname="localhost" time="2.035" errors="0" tests="0" skipped="0" disabled="0" failures="0">
</testsuite>
<testsuite name="Showing Individual Details.Given a new Individual" timestamp="2019-02-04T18:23:33" hostname="localhost" time="2.033" errors="0" tests="0" skipped="0" disabled="0" failures="0">
</testsuite>
<testsuite name="Showing Individual Details.Given a new Individual.When the Details are loaded" timestamp="2019-02-04T18:23:33" hostname="localhost" time="2.033" errors="0" tests="2" skipped="0" disabled="0" failures="0">
<testcase classname="Showing Individual Details.Given a new Individual.When the Details are loaded" name="Then all Controls are empty" time="1.106" />
<testcase classname="Showing Individual Details.Given a new Individual.When the Details are loaded" name="Then the save button is disabled" time="0.927" />
</testsuite>
由于Azure DevOps似乎只检查名称,因此我看到:
我的问题:我不确切地知道我的问题在哪里。我没有找到任何关于“真正的”BDD与Jasmine的良好资源,也似乎Jasmine Reporter无法配置那么多:https://github.com/larrymyers/jasmine-reporters
因此,我的代码完全错了,还是记者呢?如果是这种情况,是否有替代方案或者我需要以某种方式“扁平化”XML?
我同意上面的评论,创建自己的记者听起来像是要走的路。您可以根据需要格式化内容。
我最近回答了关于Jasmine记者here的另一个问题。我将测试结果重新格式化为JSON对象,并在每次测试完成后将它们存储在amazons dynamoDB中。
还有其他问题让我知道。
你可以使用useFullTestName属性:
jasmine.getEnv().addReporter(new jasmineReporters.JUnitXmlReporter({
consolidateAll: true,
useFullTestName:true,
savePath: 'e2e/output',
filePrefix: 'xmlresults'
}));