testng html报告,testng生成自定义html报告

1 package com.reporter.main;

2

3 import java.util.Collection;

4 import java.util.List;

5

6 import org.testng.ITestNGMethod;

7

8 public class DataBean {

9     private int excludeTestsSize; //未执行的test数量

10     private int passedTestsSize; //测试通过的数量

11     private int failedTestsSize; //测试失败的数量

12     private int skippedTestsSize; //测试跳过的数量

13     private int allTestsSize; //全部执行的测试的数量

14     private ITestNGMethod[] allTestsMethod; //全部执行的测试方法

15     private Collection excludeTestsMethod; //未执行的测试方法

16     private String testsTime; //测试耗时

17     private String passPercent; //测试通过率

18     private String testName; //测试方法名

19     private String className; //测试类名

20     private String duration; //单个测试周期

21     private String params; //测试用参数

22     private String description; //测试描述

23     private List output; //Reporter Output

24     private String dependMethod; //测试依赖方法

25     private Throwable throwable; //测试异常原因

26     private StackTraceElement[] stackTrace; // 异常堆栈信息

27

28     public int getExcludeTestsSize() {

29         return excludeTestsSize;

30     }

31

32     public void setExcludeTestsSize(int excludeTestsSize) {

33         this.excludeTestsSize = excludeTestsSize;

34     }

35

36     public int getPassedTestsSize() {

37         return passedTestsSize;

38     }

39

40     public void setPassedTestsSize(int passedTestsSize) {

41         this.passedTestsSize = passedTestsSize;

42     }

43

44     public int getFailedTestsSize() {

45         return failedTestsSize;

46     }

47

48     public void setFailedTestsSize(int failedTestsSize) {

49         this.failedTestsSize = failedTestsSize;

50     }

51

52     public int getSkippedTestsSize() {

53         return skippedTestsSize;

54     }

55

56     public void setSkippedTestsSize(int skippedTestsSize) {

57         this.skippedTestsSize = skippedTestsSize;

58     }

59

60     public int getAllTestsSize() {

61         return allTestsSize;

62     }

63

64     public void setAllTestsSize(int allTestsSize) {

65         this.allTestsSize = allTestsSize;

66     }

67

68     public String getPassPercent() {

69         return passPercent;

70     }

71

72     public void setPassPercent(String passPercent) {

73         this.passPercent = passPercent;

74     }

75

76     public String getTestName() {

77         return testName;

78     }

79

80     public void setTestName(String testName) {

81         this.testName = testName;

82     }

83

84     public String getClassName() {

85         return className;

86     }

87

88     public void setClassName(String className) {

89         this.className = className;

90     }

91

92     public String getDuration() {

93         return duration;

94     }

95

96     public void setDuration(String duration) {

97         this.duration = duration;

98     }

99

100     public String getParams() {

101         return params;

102     }

103

104     public void setParams(String params) {

105         this.params = params;

106     }

107

108     public String getDescription() {

109         return description;

110     }

111

112     public void setDescription(String description) {

113         this.description = description;

114     }

115

116     public List getOutput() {

117         return output;

118     }

119

120     public void setOutput(List output) {

121         this.output = output;

122     }

123

124     public String getDependMethod() {

125         return dependMethod;

126     }

127

128     public void setDependMethod(String dependMethod) {

129         this.dependMethod = dependMethod;

130     }

131

132     public Throwable getThrowable() {

133         return throwable;

134     }

135

136     public void setThrowable(Throwable throwable2) {

137         this.throwable = throwable2;

138     }

139

140     public StackTraceElement[] getStackTrace() {

141         return stackTrace;

142     }

143

144     public void setStackTrace(StackTraceElement[] stackTrace) {

145         this.stackTrace = stackTrace;

146     }

147

148     public void setTestsTime(String testsTime) {

149         this.testsTime = testsTime;

150     }

151

152     public String getTestsTime() {

153         return testsTime;

154     }

155

156     public void setAllTestsMethod(ITestNGMethod[] allTestsMethod) {

157         this.allTestsMethod = allTestsMethod;

158     }

159

160     public ITestNGMethod[] getAllTestsMethod() {

161         return allTestsMethod;

162     }

163

164     public void setExcludeTestsMethod(Collection excludeTestsMethod) {

165         this.excludeTestsMethod = excludeTestsMethod;

166     }

167

168     public Collection getExcludeTestsMethod() {

169         return excludeTestsMethod;

170     }

171

172 }

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
TestNG默认的测试报告是以XML格式输出的,如果想要生成HTML格式的测试报告,可以使用TestNG自带的`Reporter`类或第三方工具,如ExtentReports、Allure等。以下是使用Reporter类生成HTML格式测试报告的步骤: 1. 在TestNG测试类添加`@Listeners(TestReportListener.class)`注解,引入自定义的监听器类。 2. 创建一个实现`ITestListener`接口的监听器类,重写`onTestSuccess`、`onTestFailure`、`onTestSkipped`等方法,在方法使用`Reporter.log`方法输出测试结果。 3. 运行测试后,会在项目目录下生成一个`test-output`文件夹,其包含了测试结果的XML文件和截图(如果有的话)。 4. 使用TestNG自带的`Reporter`类将XML文件转换为HTML格式的测试报告,代码如下: ```java import org.testng.Reporter; import org.testng.annotations.AfterSuite; import org.testng.annotations.BeforeSuite; public class TestReportListener implements ITestListener { @BeforeSuite public void beforeSuite() { Reporter.log("<html><head><title>Test Report</title></head><body>"); } @AfterSuite public void afterSuite() { Reporter.log("</body></html>"); Reporter.flush(); } @Override public void onTestSuccess(ITestResult result) { Reporter.log("<p style=\"color:green;\">Test Passed: " + result.getName() + "</p>"); } @Override public void onTestFailure(ITestResult result) { Reporter.log("<p style=\"color:red;\">Test Failed: " + result.getName() + "</p>"); } @Override public void onTestSkipped(ITestResult result) { Reporter.log("<p style=\"color:orange;\">Test Skipped: " + result.getName() + "</p>"); } // 将其他方法省略... } ``` 在`beforeSuite`方法输出HTML文件的头部,`afterSuite`方法输出HTML文件的尾部,并调用`Reporter.flush()`方法将结果写入HTML文件。在各个测试结果的处理方法,使用`Reporter.log`方法输出HTML格式的测试结果。 5. 运行测试后,在`test-output`文件夹生成一个`emailable-report.html`文件,即为HTML格式的测试报告

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值