Allure Framework: TestNG adapter incorrectly places @AfterMethod in report

人盡茶涼 提交于 2020-01-02 05:41:13

问题


I`m using allure V1.4.8 +TestNG. It looks like TestNG adapter incorrectly places @AfterMethod in report - basically it places AfterMethod from test case into next testcase.

Here is the simple code:

    @Step("a test1")
    @Test
    public void Test1(){
    }

    @Step("a test2")
    @Test
    public void Test2(){
    }

    @Step("before method")
    @BeforeMethod
    public void beforeMethod(){     
    }

    @Step("after method")
    @AfterMethod
    public void methodCleanup()
    {   
    }

And here is the generated report:

<test-cases>
    <test-case start="1424347388060" stop="1424347388730" status="passed">
        <name>Test1</name>
        <steps>
            <step start="1424347388011" stop="1424347388014" status="passed">
                <name>before</name>
                <title>before test</title>
                <attachments/>
                <steps/>
            </step>
            <step start="1424347388036" stop="1424347388036" status="passed">
                <name>beforeMethod</name>
                <title>before method</title>
                <attachments/>
                <steps/>
            </step>
            <step start="1424347388067" stop="1424347388067" status="passed">
                <name>Test1</name>
                <title>a test1</title>
                <attachments/>
                <steps/>
            </step>
        </steps>
        <labels>
            <label name="host" value=""/>
            <label name="thread" value=""/>
        </labels>
    </test-case>
    <test-case start="1424347388747" stop="1424347389056" status="passed">
        <name>Test2</name>
        <steps>
            <step start="1424347388739" stop="1424347388739" status="passed">
                <name>methodCleanup</name>
                <title>after method</title>
                <attachments/>
                <steps/>
            </step>
            <step start="1424347388746" stop="1424347388746" status="passed">
                <name>beforeMethod</name>
                <title>before method</title>
                <attachments/>
                <steps/>
            </step>
            <step start="1424347388750" stop="1424347388750" status="passed">
                <name>Test2</name>
                <title>a test2</title>
                <attachments/>
                <steps/>
            </step>
        </steps>

     </test-case>
</test-cases>

回答1:


It's problem of TestNG adaptor. In our adaptor we use ITestListener listener and onTestSuccess, onTestFailure, onTestFailedButWithinSuccessPercentage and onTestSkipped methods to mark test as finished. But TestNG call the methods before @AfterMethod.

I don't know is there a way to handle befores and afters (maybe we can use other listener, an example IInvokedMethodListener). You can investigate this problem and send us pull request.

Hope it helps

Update

New Allure TestNG integration has support for test fixtures. So you need to upgrade to Allure 2. For more details see the docs https://docs.qameta.io/allure/2.0/#_testng



来源:https://stackoverflow.com/questions/28606521/allure-framework-testng-adapter-incorrectly-places-aftermethod-in-report

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!