【发布时间】:2019-02-04 18:49:32
【问题描述】:
我想以 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 似乎只检查名称,所以我看到:
我的问题:我不确切知道我的问题在哪里。我没有找到任何关于 Jasmine 的“真实”BDD 的好资源,而且似乎 Jasmine Reporter 无法配置那么多:https://github.com/larrymyers/jasmine-reporters
因此我的代码是完全错误的,还是实际上是记者?如果是这种情况,是否有替代方案或者我需要以某种方式“扁平化”XML?
【问题讨论】:
-
您可以编写自定义报告器以按照您想要的方式格式化 xml 文件。它实际上比你想象的要容易。查看此处了解如何开始jasmine.github.io/2.1/custom_reporter.html
标签: jasmine protractor azure-devops bdd