2017-04-19 101 views
0

我有一对量角器测试脚本。我的目标是根据脚本和结果生成一些报告。如何将附加信息附加到测试规范?

有有一些,我想连接到每个测试,像一个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 
    } 
} 

而且具有与额外的信息输出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> 

如果不能添加代码本身,是有办法,这可以作为意见或可以很容易地分析其他元素?最好使用现有的工具或茉莉花/量角器功能?

回答

0

关于为it调用(测试规范)的额外信息:

茉莉花使用对象result是测试规范的一部分,并要求当使用它作为result参数记者的specStartedspecDone

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

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

茉莉也使用对象result那就是测试套件的一部分,并要求当传递它作为result参数记者的suiteStartedsuiteDone

用于测试套件的属性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 
}); 

添加额外信息的expect语句是更复杂一点,因为通过expect函数返回的对象不会传递给记者也不添加到testSpec.result.passedExpectations也不添加到testSpec.result.failedExpectations阵列。

相关问题