有没有一种(简单)的方法可以生成包含测试结果的HTML报告? 我目前正在使用JUnit以及Selenium来测试Web应用程序UI。
PS:由于项目结构的限制,我不能使用Ant :(
有没有一种(简单)的方法可以生成包含测试结果的HTML报告? 我目前正在使用JUnit以及Selenium来测试Web应用程序UI。
PS:由于项目结构的限制,我不能使用Ant :(
我发现上述答案非常有用,但不是真正的通用目的,它们都需要一些其他主要的构建系统,如Ant或Maven。
我想生成一个简单的一次性命令报告,可以从任何地方调用(从构建、测试或只是我自己),所以我创建了junit2html,可以在这里找到:https://github.com/inorton/junit2html
您可以通过执行以下操作安装它:
pip install junit2html
junit2html results.xml output.html
。 - luatorjunit2html test-results --merge test-results\reports.xml
,然后将单个 .xml 文件转换为 .html 文件 junit2html test-results\reports.xml test-results\reports.html
。这里的示例使用的是 Windows 路径语法。 - AdamE你可以很容易地通过ant完成这个操作。以下是一个build.xml文件,用于执行此操作。
<project name="genTestReport" default="gen" basedir=".">
<description>
Generate the HTML report from JUnit XML files
</description>
<target name="gen">
<property name="genReportDir" location="${basedir}/unitTestReports"/>
<delete dir="${genReportDir}"/>
<mkdir dir="${genReportDir}"/>
<junitreport todir="${basedir}/unitTestReports">
<fileset dir="${basedir}">
<include name="**/TEST-*.xml"/>
</fileset>
<report format="frames" todir="${genReportDir}/html"/>
</junitreport>
</target>
</project>
这将查找格式为 TEST-*.xml 的文件,并生成报告到名为 unitTestReports 的文件夹中。
要运行此命令(假设上面的文件名为 buildTestReports.xml),请在终端中运行以下命令:
ant -buildfile buildTestReports.xml
junit-viewer --results=surefire-reports --save=file_location.html
。
--results=
为包含XML文件(测试报告)的目录。--minify-false
可以避免一些失败。 - Valentin Kantor我发现xunit-viewer
,它已经废弃了由@daniel-kristof-kiss提到的junit-viewer
。
这个工具非常简单,可以自动递归收集所有ANT JUnit XML格式的相关文件,并创建一个单独的HTML文件,具有过滤和其他优秀功能。
我使用它上传Travis构建的测试结果,因为Travis没有其他支持来收集标准格式的测试结果输出。
import static org.junit.Assert.assertTrue;
import org.junit.Test;
public class TestClass2 extends WatchManClassConsole {
@Test public void testScript1() {
assertTrue(1 < 2); >
}
@Test public void testScript2() {
assertTrue(1 > 2);
}
@Test public void testScript3() {
assertTrue(1 < 2);
}
@Test public void testScript4() {
assertTrue(1 > 2);
}
}
import org.junit.Rule;
import org.junit.rules.TestRule;
import org.junit.rules.TestWatcher;
import org.junit.runner.Description;
import org.junit.runners.model.Statement;
public class WatchManClassConsole {
@Rule public TestRule watchman = new TestWatcher() {
@Override public Statement apply(Statement base, Description description) {
return super.apply(base, description);
}
@Override protected void succeeded(Description description) {
System.out.println(description.getDisplayName() + " " + "success!");
}
@Override protected void failed(Throwable e, Description description) {
System.out.println(description.getDisplayName() + " " + e.getClass().getSimpleName());
}
};
}
2. Use the Allure Reporting framework
Allure framework can help with generating HTML reports for your Selenium WebDriver projects.
The reporting framework is very flexible and it works with many programming languages and unit testing frameworks.
You can read everything about it at http://allure.qatools.ru/.
You will need the following dependencies and plugins to be added to your pom.xml file
See more details including code samples on this article: http://test-able.blogspot.com/2015/10/create-selenium-html-reports-with-allure-framework.html