Junit create report without ant/maven

笑着哭i 提交于 2019-12-04 20:33:47

You will need the ant library. But with this code you can create an XML report and use it in other pograms. Such as Jenkins.

public static void getTest(){
    String pathToReports = "C:\\path\\to\\the\\Reports";
    Project project = new Project();

    try {
        new File(pathToReports).mkdir();
        JUnitTask task = new JUnitTask();

        project.setProperty("java.io.tmpdir",pathToReports);
        task.setProject(project);

        FormatterElement.TypeAttribute type = new FormatterElement.TypeAttribute();
        type.setValue("xml");

        FormatterElement formater = new FormatterElement();   
        formater.setType(type);
        task.addFormatter(formater);

        JUnitTest test = new JUnitTest(YOURTEST.class.getName());
        test.setTodir(new File(pathToReports));

        task.addTest(test);         
        task.execute(); 
    } catch (Exception e) {
    }

}

Don't think so. But you might be able to use ant as a library instead of a tool, and use the same code that the tool uses to generate these reports.

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