Java源码示例:com.aventstack.extentreports.Status
示例1
@Override
public void generateReport(List<XmlSuite> xmlSuites, List<ISuite> suites, String outputDirectory) {
ExtentService.getInstance().setReportUsesManualConfiguration(true);
ExtentService.getInstance().setAnalysisStrategy(AnalysisStrategy.SUITE);
for (ISuite suite : suites) {
Map<String, ISuiteResult> result = suite.getResults();
for (ISuiteResult r : result.values()) {
ITestContext context = r.getTestContext();
ExtentTest suiteTest = ExtentService.getInstance().createTest(r.getTestContext().getSuite().getName());
buildTestNodes(suiteTest, context.getFailedTests(), Status.FAIL);
buildTestNodes(suiteTest, context.getSkippedTests(), Status.SKIP);
buildTestNodes(suiteTest, context.getPassedTests(), Status.PASS);
}
}
for (String s : Reporter.getOutput()) {
ExtentService.getInstance().setTestRunnerOutput(s);
}
ExtentService.getInstance().flush();
}
示例2
public static Report filter(Report report, Set<Status> statusList) {
if (report.getTestList().isEmpty())
return report;
Report filtered = Report.builder().build();
filtered.getLogs().addAll(report.getLogs());
filtered.setStartTime(report.getStartTime());
filtered.setEndTime(report.getEndTime());
List<Test> list = report.getTestList().stream()
.filter(x -> statusList.contains(x.getStatus()))
.collect(Collectors.toList());
list.forEach(filtered.getTestList()::add);
filtered.getStats().update(list);
Set<NamedAttributeContext<Author>> authorCtx = new NamedAttributeTestContextFilter<Author>()
.filter(report.getAuthorCtx(), statusList);
authorCtx.stream().forEach(x -> filtered.getAuthorCtx().addContext(x.getAttr(), x.getTestList()));
Set<NamedAttributeContext<Category>> categoryCtx = new NamedAttributeTestContextFilter<Category>()
.filter(report.getCategoryCtx(), statusList);
categoryCtx.stream().forEach(x -> filtered.getCategoryCtx().addContext(x.getAttr(), x.getTestList()));
Set<NamedAttributeContext<Device>> deviceCtx = new NamedAttributeTestContextFilter<Device>()
.filter(report.getDeviceCtx(), statusList);
deviceCtx.stream().forEach(x -> filtered.getDeviceCtx().addContext(x.getAttr(), x.getTestList()));
return filtered;
}
示例3
private final void update(final List<? extends RunResult> list, final Map<Status, Long> countMap,
final Map<Status, Float> percentageMap) {
if (list == null)
return;
Map<Status, Long> map = list.stream().collect(
Collectors.groupingBy(RunResult::getStatus, Collectors.counting()));
Arrays.asList(Status.values()).forEach(x -> map.putIfAbsent(x, 0L));
countMap.putAll(map);
if (list.isEmpty()) {
percentageMap.putAll(
map.entrySet().stream()
.collect(Collectors.toMap(e -> e.getKey(), e -> Float.valueOf(e.getValue()))));
return;
}
Map<Status, Float> pctMap = map.entrySet().stream()
.collect(Collectors.toMap(e -> e.getKey(),
e -> Float.valueOf(e.getValue() * 100 / list.size())));
percentageMap.putAll(pctMap);
}
示例4
@org.testng.annotations.Test
public void statsAll() {
Report report = Report.builder().build();
report.getStats().update(report.getTestList());
// check if all Status fields are present
Arrays.asList(Status.values()).forEach(x -> Assert.assertTrue(report.getStats().getParent().containsKey(x)));
Arrays.asList(Status.values()).forEach(x -> Assert.assertTrue(report.getStats().getChild().containsKey(x)));
Arrays.asList(Status.values())
.forEach(x -> Assert.assertTrue(report.getStats().getGrandchild().containsKey(x)));
Assert.assertEquals(report.getStats().getParent().get(Status.PASS).longValue(), 0);
Assert.assertEquals(report.getStats().getParent().get(Status.FAIL).longValue(), 0);
Assert.assertEquals(report.getStats().getParent().get(Status.SKIP).longValue(), 0);
Assert.assertEquals(report.getStats().getParent().get(Status.WARNING).longValue(), 0);
Assert.assertEquals(report.getStats().getParent().get(Status.INFO).longValue(), 0);
Assert.assertEquals(report.getStats().getChild().get(Status.PASS).longValue(), 0);
Assert.assertEquals(report.getStats().getChild().get(Status.FAIL).longValue(), 0);
Assert.assertEquals(report.getStats().getChild().get(Status.SKIP).longValue(), 0);
Assert.assertEquals(report.getStats().getChild().get(Status.WARNING).longValue(), 0);
Assert.assertEquals(report.getStats().getChild().get(Status.INFO).longValue(), 0);
Assert.assertEquals(report.getStats().getGrandchild().get(Status.PASS).longValue(), 0);
Assert.assertEquals(report.getStats().getGrandchild().get(Status.FAIL).longValue(), 0);
Assert.assertEquals(report.getStats().getGrandchild().get(Status.SKIP).longValue(), 0);
Assert.assertEquals(report.getStats().getGrandchild().get(Status.WARNING).longValue(), 0);
Assert.assertEquals(report.getStats().getGrandchild().get(Status.INFO).longValue(), 0);
}
示例5
@org.testng.annotations.Test
public void statsTestStatus() {
Test test = TestService.createTest("Test");
Report report = Report.builder().build();
report.getTestList().add(test);
report.getStats().update(report.getTestList());
// check if all Status fields are present
Arrays.asList(Status.values()).forEach(x -> Assert.assertTrue(report.getStats().getParent().containsKey(x)));
Arrays.asList(Status.values()).forEach(x -> Assert.assertTrue(report.getStats().getChild().containsKey(x)));
Arrays.asList(Status.values())
.forEach(x -> Assert.assertTrue(report.getStats().getGrandchild().containsKey(x)));
test.setStatus(Status.FAIL);
report.getStats().update(report.getTestList());
Assert.assertEquals(report.getStats().getParent().get(Status.PASS).longValue(), 0);
Assert.assertEquals(report.getStats().getParent().get(Status.FAIL).longValue(), 1);
}
示例6
@org.testng.annotations.Test
public void statsChildStatus() {
Test test = TestService.createTest("Test");
Test node = TestService.createTest("Node");
node.setStatus(Status.SKIP);
test.addChild(node);
Report report = Report.builder().build();
report.getTestList().add(test);
report.getStats().update(report.getTestList());
// check if all Status fields are present
Arrays.asList(Status.values()).forEach(x -> Assert.assertTrue(report.getStats().getParent().containsKey(x)));
Arrays.asList(Status.values()).forEach(x -> Assert.assertTrue(report.getStats().getChild().containsKey(x)));
Arrays.asList(Status.values())
.forEach(x -> Assert.assertTrue(report.getStats().getGrandchild().containsKey(x)));
Assert.assertEquals(report.getStats().getParent().get(Status.PASS).longValue(), 0);
Assert.assertEquals(report.getStats().getParent().get(Status.SKIP).longValue(), 1);
Assert.assertEquals(report.getStats().getChild().get(Status.PASS).longValue(), 0);
Assert.assertEquals(report.getStats().getChild().get(Status.SKIP).longValue(), 1);
}
示例7
@org.testng.annotations.Test
public void statsGrandchildStatus() {
Test test = TestService.createTest("Test");
Test node = TestService.createTest("Node");
Test grandchild = TestService.createTest("Grandchild");
grandchild.setStatus(Status.FAIL);
node.addChild(grandchild);
test.addChild(node);
Report report = Report.builder().build();
report.getTestList().add(test);
report.getStats().update(report.getTestList());
// check if all Status fields are present
Arrays.asList(Status.values()).forEach(x -> Assert.assertTrue(report.getStats().getParent().containsKey(x)));
Arrays.asList(Status.values()).forEach(x -> Assert.assertTrue(report.getStats().getChild().containsKey(x)));
Arrays.asList(Status.values())
.forEach(x -> Assert.assertTrue(report.getStats().getGrandchild().containsKey(x)));
Assert.assertEquals(report.getStats().getParent().get(Status.PASS).longValue(), 0);
Assert.assertEquals(report.getStats().getParent().get(Status.FAIL).longValue(), 1);
Assert.assertEquals(report.getStats().getChild().get(Status.PASS).longValue(), 0);
Assert.assertEquals(report.getStats().getChild().get(Status.FAIL).longValue(), 1);
Assert.assertEquals(report.getStats().getGrandchild().get(Status.PASS).longValue(), 0);
Assert.assertEquals(report.getStats().getGrandchild().get(Status.FAIL).longValue(), 1);
}
示例8
@org.testng.annotations.Test
public void reportTestHasStatus() {
Test test = TestService.createTest("Test");
Log skip = Log.builder().status(Status.SKIP).build();
Log pass = Log.builder().status(Status.PASS).build();
Report report = Report.builder().build();
report.getTestList().add(test);
Assert.assertTrue(report.anyTestHasStatus(Status.PASS));
Assert.assertFalse(report.anyTestHasStatus(Status.SKIP));
test.addLog(skip);
Assert.assertFalse(report.anyTestHasStatus(Status.PASS));
Assert.assertTrue(report.anyTestHasStatus(Status.SKIP));
test.addLog(pass);
Assert.assertFalse(report.anyTestHasStatus(Status.PASS));
Assert.assertTrue(report.anyTestHasStatus(Status.SKIP));
}
示例9
@Test
public void statusFilterable() {
ExtentReports extent = new ExtentReports();
String path = path();
ExtentSparkReporter spark = new ExtentSparkReporter(path)
.filter()
.statusFilter()
.as(new Status[]{Status.FAIL})
.apply();
extent.attachReporter(spark);
extent.createTest(PARENT).pass("Pass");
extent.createTest(CHILD).fail("Fail");
extent.flush();
assertFileExists(path);
Assert.assertEquals(spark.getReport().getTestList().size(), 1);
Assert.assertEquals(spark.getReport().getTestList().get(0).getName(), CHILD);
}
示例10
@Test
public void statusFilterableNode() {
ExtentReports extent = new ExtentReports();
String path = path();
ExtentSparkReporter spark = new ExtentSparkReporter(path)
.filter()
.statusFilter()
.as(new Status[]{Status.FAIL})
.apply();
extent.attachReporter(spark);
extent.createTest(PARENT).pass("Pass");
extent.createTest(CHILD).pass("Pass")
.createNode(GRANDCHILD).fail("Fail");
extent.flush();
assertFileExists(path);
Assert.assertEquals(spark.getReport().getTestList().size(), 1);
Assert.assertEquals(spark.getReport().getTestList().get(0).getName(), CHILD);
Assert.assertEquals(spark.getReport().getTestList().get(0).getChildren().size(), 1);
Assert.assertEquals(spark.getReport().getTestList().get(0).getChildren().get(0).getName(), GRANDCHILD);
}
示例11
@Override
public void generateReport(List<XmlSuite> xmlSuites, List<ISuite> suites, String outputDirectory) {
ExtentService.getInstance().setReportUsesManualConfiguration(true);
ExtentService.getInstance().setAnalysisStrategy(AnalysisStrategy.SUITE);
for (ISuite suite : suites) {
Map<String, ISuiteResult> result = suite.getResults();
for (ISuiteResult r : result.values()) {
ITestContext context = r.getTestContext();
ExtentTest suiteTest = ExtentService.getInstance().createTest(r.getTestContext().getSuite().getName());
buildTestNodes(suiteTest, context.getFailedTests(), Status.FAIL);
buildTestNodes(suiteTest, context.getSkippedTests(), Status.SKIP);
buildTestNodes(suiteTest, context.getPassedTests(), Status.PASS);
}
}
for (String s : Reporter.getOutput()) {
ExtentService.getInstance().setTestRunnerOutput(s);
}
ExtentService.getInstance().flush();
}
示例12
private void buildTestNodes(ExtentTest suiteTest, IResultMap tests, Status status) {
ExtentTest node;
if (tests.size() > 0) {
for (ITestResult result : tests.getAllResults()) {
node = suiteTest.createNode(result.getMethod().getMethodName(), result.getMethod().getDescription());
String groups[] = result.getMethod().getGroups();
ExtentTestCommons.assignGroups(node, groups);
if (result.getThrowable() != null) {
node.log(status, result.getThrowable());
} else {
node.log(status, "Test " + status.toString().toLowerCase() + "ed");
}
node.getModel().getLogContext().getAll().forEach(x -> x.setTimestamp(getTime(result.getEndMillis())));
node.getModel().setStartTime(getTime(result.getStartMillis()));
node.getModel().setEndTime(getTime(result.getEndMillis()));
}
}
}
示例13
public static synchronized void log(ITestResult result, Boolean createTestAsChild) {
String msg = "Test ";
Status status = Status.PASS;
switch (result.getStatus()) {
case ITestResult.SKIP:
status = Status.SKIP;
msg += "skipped";
break;
case ITestResult.FAILURE:
status = Status.FAIL;
msg += "failed";
break;
default:
msg += "passed";
break;
}
if (ExtentTestManager.getTest(result) == null) {
ExtentTestManager.createMethod(result, createTestAsChild);
}
if (result.getThrowable() != null) {
ExtentTestManager.getTest(result).log(status, result.getThrowable());
return;
}
ExtentTestManager.getTest(result).log(status, msg);
}
示例14
@Override
public Response intercept(Chain chain) throws IOException {
Request request = chain.request();
Response response = chain.proceed(request);
long time = response.receivedResponseAtMillis() - response.sentRequestAtMillis();
if (time > 100) {
MyReporter.report.log(Status.WARNING, MyReporter.getTestName() + " 接口耗时:" + time);
}
return response;
}
示例15
@Override
public Report filterAndGet(Report report, Set<Status> set) {
if (report == null || report.getTestList().isEmpty())
return report;
if (set != null)
return ReportFilterService.filter(report, set);
return report;
}
示例16
private synchronized void refresh(Test test) {
if (test.getStatus() == Status.PASS)
passed++;
else if (test.getStatus() == Status.FAIL)
failed++;
else if (test.getStatus() == Status.SKIP)
skipped++;
else
others++;
}
示例17
public Set<NamedAttributeContext<T>> filter(NamedAttributeContextManager<T> mgr, Set<Status> status) {
NamedAttributeContextManager<T> newmgr = new NamedAttributeContextManager<T>();
mgr.getSet().stream()
.forEach(x -> newmgr.addContext(x.getAttr(), x.getTestList()));
List<Test> unwantedList = newmgr.getSet().stream()
.flatMap(x -> x.getTestList().stream())
.filter(x -> !status.contains(x.getStatus()))
.collect(Collectors.toList());
unwantedList.forEach(newmgr::removeTest);
return newmgr.getSet();
}
示例18
public final Status getStatus() {
List<Status> list = testList
.stream()
.map(x -> x.getStatus())
.collect(Collectors.toList());
return Status.max(list);
}
示例19
private void computeStatus(Test t) {
Set<Status> set = new HashSet<>();
Iterator<Log> iter = new ArrayList<>(t.getLogs()).iterator();
while (iter.hasNext())
set.add(iter.next().getStatus());
set.add(t.getStatus());
t.setStatus(Status.max(set));
if (t.getParent() != null) {
t.getParent().setStatus(Status.max(t.getStatus(), t.getParent().getStatus()));
computeStatus(t.getParent());
}
}
示例20
@org.testng.annotations.Test
public void statsSize() {
Test test = TestService.createTest("Test");
Report report = Report.builder().build();
report.getTestList().add(test);
Assert.assertEquals(report.getStats().getParent().size(), 0);
report.getStats().update(report.getTestList());
Assert.assertEquals(report.getStats().getParent().size(), Status.values().length);
}
示例21
@org.testng.annotations.Test
public void testHasScreenCaptureDeepLog() {
Test test = getTest();
Log log = Log.builder().status(Status.PASS).details("").build();
log.addMedia(ScreenCapture.builder().path("/img.png").build());
test.addLog(log);
Assert.assertFalse(test.hasScreenCapture());
Assert.assertTrue(TestService.testHasScreenCapture(test, true));
}
示例22
@org.testng.annotations.Test
public void testHasScreenCaptureDeepNodeLog() {
Test test = getTest();
Test node = getTest();
test.getChildren().add(node);
Log log = Log.builder().status(Status.PASS).details("").build();
log.addMedia(ScreenCapture.builder().path("/img.png").build());
node.addLog(log);
Assert.assertFalse(test.hasScreenCapture());
Assert.assertTrue(TestService.testHasScreenCapture(test, true));
}
示例23
@org.testng.annotations.Test
public void testEntities(Method method) {
Test test = TestService.createTest(method.getName());
Assert.assertEquals(test.getAuthorSet().size(), 0);
Assert.assertEquals(test.getDeviceSet().size(), 0);
Assert.assertEquals(test.getCategorySet().size(), 0);
Assert.assertEquals(test.getChildren().size(), 0);
Assert.assertTrue(test.isLeaf());
Assert.assertEquals(test.getLevel().intValue(), 0);
Assert.assertEquals(test.getStatus(), Status.PASS);
Assert.assertNull(test.getDescription());
}
示例24
@org.testng.annotations.Test
public void addLogToTest() {
Test test = getTest();
Log log = Log.builder().build();
test.addLog(log);
Assert.assertEquals(log.getSeq().intValue(), 0);
Assert.assertEquals(test.getLogs().size(), 1);
Assert.assertEquals(test.getStatus(), Status.PASS);
Assert.assertEquals(log.getStatus(), Status.PASS);
}
示例25
@org.testng.annotations.Test
public void addSkipLogToTest() {
Test test = getTest();
Log log = Log.builder().status(Status.SKIP).build();
test.addLog(log);
Assert.assertEquals(test.getStatus(), Status.SKIP);
Assert.assertEquals(log.getStatus(), Status.SKIP);
}
示例26
@org.testng.annotations.Test
public void addFailLogToTest() {
Test test = getTest();
Log log = Log.builder().status(Status.FAIL).build();
test.addLog(log);
Assert.assertEquals(test.getStatus(), Status.FAIL);
Assert.assertEquals(log.getStatus(), Status.FAIL);
}
示例27
@org.testng.annotations.Test
public void testHasLog() {
Test test = getTest();
Assert.assertFalse(test.hasLog());
Log log = Log.builder().status(Status.FAIL).build();
test.addLog(log);
Assert.assertTrue(test.hasLog());
}
示例28
@org.testng.annotations.Test
public void testStatusWithLog() {
Test test = getTest();
Assert.assertEquals(test.getStatus(), Status.PASS);
Log log = Log.builder().status(Status.FAIL).build();
test.addLog(log);
Assert.assertEquals(test.getStatus(), Status.FAIL);
}
示例29
@org.testng.annotations.Test
public void testStatusWithLogStatusChanged() {
Test test = getTest();
Assert.assertEquals(test.getStatus(), Status.PASS);
Log log = Log.builder().status(Status.SKIP).build();
test.addLog(log);
Assert.assertEquals(test.getStatus(), Status.SKIP);
log.setStatus(Status.FAIL);
test.updateResult();
Assert.assertEquals(test.getStatus(), Status.FAIL);
}
示例30
@org.testng.annotations.Test
public void computeTestStatusSkipLog() {
Test test = getTest();
test.getLogs().add(Log.builder().status(Status.SKIP).build());
test.updateResult();
Assert.assertEquals(test.getStatus(), Status.SKIP);
}