【问题标题】:Allure Framework: TestNG adapter incorrectly places @AfterMethod in reportAllure 框架:TestNG 适配器错误地将@AfterMethod 放置在报告中
【发布时间】:2015-02-19 12:32:15
【问题描述】:

我正在使用 allure V1.4.8 +TestNG。看起来 TestNG 适配器错误地将 @AfterMethod 放置在报告中 - 基本上它将 AfterMethod 从测试用例放入下一个测试用例。

下面是简单的代码:

    @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()
    {   
    }

这是生成的报告:

<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>

【问题讨论】:

    标签: allure


    【解决方案1】:

    TestNG 适配器的问题。在我们的适配器中,我们使用ITestListener 侦听器和onTestSuccessonTestFailureonTestFailedButWithinSuccessPercentageonTestSkipped 方法将测试标记为已完成。但是TestNG 调用方法before @AfterMethod

    我不知道有没有办法处理beforesafters(也许我们可以使用其他监听器,例如IInvokedMethodListener)。您可以调查此问题并向我们发送拉取请求。

    希望对你有帮助

    更新

    新的 Allure TestNG 集成支持测试夹具。所以你需要升级到 Allure 2。更多细节参见文档https://docs.qameta.io/allure/2.0/#_testng

    【讨论】:

    • 我面临着完全相同的问题。我对listners了解不多,请您建议我现在应该做什么来解决这个问题。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-07-20
    • 2017-10-17
    相关资源
    最近更新 更多