【问题标题】:Allure framework isn’t producing detailed reports when using JunitCore使用 JunitCore 时,Allure 框架不会生成详细的报告
【发布时间】:2015-07-19 08:13:55
【问题描述】:

我正在使用 JUnitCore 运行 Junit 测试。 我正在尝试使用 allure 框架进行报告。 文档建议使用JUnitCore.addListener() 添加 AllureRunListener。 但是,无论我如何尝试这样做,魅力报告都是空的。 它们显示了运行的测试,也失败了断言,但没有@step,@attachment

我尝试使用 JunitCore 而不是 maven 插件搜索使用 allure 报告的示例,但找不到任何东西(使用 maven 运行测试工作正常,并且 allure 报告一切正常)。

如何实现?

JunitCore 运行 -

 public static void main(String[] args) {
        AllureRunListener allureListener =new AllureRunListener();

        JUnitCore core = new JUnitCore();
        core.addListener(allureListener);
        Result result = core.run(BuildNetworkTest.class);
        //Result result = core.runClasses(TestSuite.class);

        for (Failure failure : result.getFailures()) {
            System.out.println(failure.toString());
        }
        System.out.println(result.wasSuccessful());
    }

测试-

 @Test
    public void BuildNetwork(){
        try {
            Build buildFactory = new Build();
            System.out.println("running the BuildNetwork test in TestRunnerPac.BuildNetwork");
            StepTemp();
            attachmentTemp();
        }catch (Exception e)
        {
            System.out.println(e.getMessage());
            e.printStackTrace();
        }
    }

  @Step
    public void StepTemp(){
        assertThat("stepTemp").isEqualTo("stepTemp");
        System.out.println("In stepTemp..");
    }
    @Attachment
    public String attachmentTemp(){
        return "this is an attachmentTemp , hope it will work..";
    }

【问题讨论】:

    标签: junit report allure test-reporting


    【解决方案1】:

    确保使用指向 aspectjweaver.jar-javaagent 参数启动您的测试,例如:

    java -javaagent:"/path/to/aspectjweaver.jar" <the rest of the arguments>
    

    如果您使用的是 Maven Surefire 插件,请查看以下example 以了解如何执行此操作。

    【讨论】:

    • 这修复了它。谢谢。
    猜你喜欢
    • 2017-10-17
    • 2018-01-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-12-24
    • 1970-01-01
    • 1970-01-01
    • 2019-07-13
    相关资源
    最近更新 更多