如何将额外信息附加到测试规范?

fro*_*koi 4 jasmine protractor

我有几个量角器测试脚本。我的目标是根据脚本和结果生成一些报告。

我想在每个测试中附加一些附加信息,例如 ID 或参考编号。有没有办法将它添加到每个it规格中?我不需要茉莉花或量角器来处理这些信息,最多也只是将它包含在测试结果输出文件中。

我想要这样的东西:

describe('Module A Test Suite', function () {
    // note parameter with extra info
    it('This is a test', {testId: 123, release: "v2.0.5"}, function () {

        //note parameter with extra info
        expect({description: "Verify link is shown", priority: 2}, element(by.id('Home')).isPresent()).toBe(true);

        // more tests and expect's here
    }
}
Run Code Online (Sandbox Code Playgroud)

并在输出 xml 中有一些包含额外信息的部分。

也许会导致这样的事情:

<testsuites>
    <testsuite name="chrome.Module A Test Suite" timestamp="2016-11-22T11:22:45" hostname="localhost" time="77.753" errors="0" tests="8" skipped="0" disabled="0" failures="3">
        <extras testId="123" release="v2.0.5" />
        <testcase classname="chrome.Module A Test Suite" name="This is a test" >
            <extras description="Verify link is shown" priority="2"/>
        </testcase>
    </testsuite>
</testsuites>
Run Code Online (Sandbox Code Playgroud)

如果这不能作为代码本身添加,是否有办法将其添加为注释或其他易于解析的元素?最好使用现有工具或茉莉花/量角器功能?

fro*_*koi 7

关于it通话的额外信息(测试规范):

Jasmine 使用作为result测试规范一部分的对象,并result在调用报告者的specStarted和时将其用作参数specDone

result对象是从it函数返回的对象的属性。

关于describe调用的额外信息(测试套件):

Jasmine 还使用作为result测试套件一部分的对象,并result在调用报告器的suiteStarted和时将其作为参数传递suiteDone

result测试套件的属性可以通过this用于describe.

因此,要为其分配额外的数据,我们可以执行以下操作

 describe('Module A Test Suite', function () {
    // the following line attaches information to the test suite
    this.result.extra_suite_data = {suiteInfo: "extra info"};

    // note parameter with extra info
    it('This is a test', function () {

        //note parameter with extra info
        expect(element(by.id('Home')).isPresent()).toBe(true);

    })
    .result.extra_spec_data = {testId: 123, release: "v2.0.5"};
    // the line above adds `extra_data` to the `result` property 
    // of the object returned by `it`. Attaching the data to the
    // test spec
});
Run Code Online (Sandbox Code Playgroud)

expect语句添加额外信息稍微复杂一些,因为expect函数返回的对象没有传递给报告器,也testSpec.result.passedExpectations没有添加到testSpec.result.failedExpectations数组中。

  • 我认为这主要是通过检查源代码,所以如果他们改变他们的底层实现,这可能会停止工作 (2认同)