2017-04-19 14 views
0

私は2つの分度器テストスクリプトを持っています。私の目標は、スクリプトと結果に基づいていくつかのレポートを生成することです。テスト仕様に追加情報を添付するにはどうすればよいですか?

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> 

、これは簡単に解析することができ、コメントや他の要素として追加することができる方法はありますか?好ましくは、既存の工具またはジャスミン/分度器の機能性を備えているか? itコール(テスト仕様)のための追加情報については

答えて

0

ジャスミンは、テスト仕様の一部であり、記者のspecStartedspecDoneを呼び出すときresult、それをパラメータとして使用するオブジェクトresultを使用しています。

resultオブジェクトは、it関数から返されたオブジェクトのプロパティです。 describeコール(テストスイート)のための追加情報については

ジャスミンはまた、テストスイートの一部であるオブジェクトresultを使用し、記者のsuiteStartedsuiteDoneを呼び出すときresult、それをパラメータとして渡します。

テストスイートのプロパティresultは、describeで使用されている関数の中でthisでアクセスできます。だから我々はexpect文のための余分な情報を追加

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関数によって返されたオブジェクトは記者に渡されていないことを考えると、もう少し複雑ですtestSpec.result.passedExpectationsに加えたり、配列をtestSpec.result.failedExpectationsに追加することもできません。