Junit不使用ant/maven创建报告 [英] Junit create report without ant/maven
问题描述
是否可以在没有Ant或Maven的情况下从JUnit创建报告?因为我用Velocitycode调用测试,而Velocitycodes调用了方法.然后该方法调用所有测试.因此,我可以从中获取响应,包括失败/错误/运行等.但是我想用它创建报告.还是我需要自己创建html内容?
Is it possible to create a report from JUnit without Ant or Maven? Because I call the tests with velocitycode, and the velocitycodes calls a method. And that method calls all the tests. So I can get a response from it, the failures/errors/runs etc. But I want to create a report with it.. Or do I need to create html stuff by myself?
我用Java创建了方法和测试方法,所以我将用Java处理所有事情,除了调用,就是用Velocity代码进行.
I created the methods and testmethods in Java, so I will do everything in Java, except the call, thats in Velocity code.
速度代码:
$ {custom.test}
${custom.test}
Java代码:
public void getTest(){
junit.textui.TestRunnerRunner =新的junit.textui.TestRunner();
TestResult testresult = Junit.textui.TestRunner.run(runner.getTest(MyTestClass.class.getName()));
}
public void getTest(){
junit.textui.TestRunner runner = new junit.textui.TestRunner();
TestResult testresult = Junit.textui.TestRunner.run(runner.getTest(MyTestClass.class.getName()));
}
推荐答案
您将需要ant库.但是使用此代码,您可以创建XML报告并在其他图表中使用它.例如詹金斯(Jenkins).
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) {
}
}
这篇关于Junit不使用ant/maven创建报告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!