当前位置: 首页 > 知识库问答 >
问题:

当类与TestNG并行运行时,无法生成扩展报告

宰宣
2023-03-14

当类与 TestNG 并行运行时,我们不会获得范围报告,但 TestNG 报告会更新。请找到我正在使用的示例代码和版本。如果我们只运行一个类(TestClass1.java),则将生成范围报告。

硒版本3.4.0

范围报告版本:3.0.6

扩展报告库.java

ExtentHtmlReporter htmlReporter;
ExtentReports extent;
ExtentTest test;


@BeforeTest
public void setUp()
{
    //where we need to generate the report
    htmlReporter = new ExtentHtmlReporter(System.getProperty("user.dir")+"/test-output/MyReport.html");
    extent = new ExtentReports();
    extent.attachReporter(htmlReporter);

    // Set our document title, theme etc..
    htmlReporter.config().setDocumentTitle("My Test Report");
    htmlReporter.config().setReportName("Test Report");
    htmlReporter.config().setTestViewChartLocation(ChartLocation.TOP);
    htmlReporter.config().setTheme(Theme.DARK); 

}

@AfterMethod
public void getResult(ITestResult result)
{
    if(result.getStatus()==ITestResult.FAILURE)
    {
        test.log(Status.FAIL, MarkupHelper.createLabel(result.getName() + "Test Case failed due to below issues", ExtentColor.RED));
        test.fail(result.getThrowable());
    }

    else if(result.getStatus()==ITestResult.SUCCESS)
    {
        test.log(Status.PASS, MarkupHelper.createLabel(result.getName() + "Test Case Passed", ExtentColor.GREEN));
    }

    else
    {
        test.log(Status.SKIP, MarkupHelper.createLabel(result.getName() + "Test Case skipped", ExtentColor.YELLOW));
    }

}

@AfterSuite
public void tearDown()
{
    extent.flush();
}

测试类1.java

@Test
public void functionality1Test1()
{
    test = extent.createTest("functionality1Test1");
    Assert.assertTrue(1 > 0);
}

@Test
public void functionality1Test2()
{
    test = extent.createTest("functionality1Test2");
    Assert.assertEquals("Google", "goo");
}

@Test
public void functionality1Test3()
{
    test = extent.createTest("functionality1Test3");
    Assert.assertNotEquals("Google", "Google");
}    

TestClass2.java

@Test
public void functionality2Test1()
{
    test = extent.createTest("functionality2Test1");
    Assert.assertTrue(1 > 0);
}

@Test
public void functionality2Test2()
{
    test = extent.createTest("functionality2Test2");
    Assert.assertEquals("Google", "goo");
}

@Test
public void functionality2Test3()
{
    test = extent.createTest("functionality2Test3");
    Assert.assertNotEquals("Google", "Google");
}

testng.xml

`<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Suite" parallel="classes">
  <test name="Test">
    <classes>
      <class name="TestExtentReport.TestClass1"/>
      <class name="TestExtentReport.TestClass2"/>
    </classes>
  </test> <!-- Test -->
</suite> <!-- Suite -->`

共有2个答案

东弘扬
2023-03-14

这3个变量是每个类调用实例变量,它们需要被初始化,所以将它们声明为static可以解决你的问题。

ExtentHtmlReporter htmlReporter;
ExtentReports extent;
ExtentTest test;

宣布它们为-

static ExtentHtmlReporter htmlReporter;
static ExtentReports extent;
static ExtentTest test; 

我试过同样的代码。对我来说很好。

让我知道那是否有效。

酆君墨
2023-03-14

使用范围报告jar 3. x. x

并在基类中使用范围变量,例如:

static ExtentHtmlReporter htmlReporter; 
static ExtentReports reports;
ExtentTest logger;
 类似资料:
  • 问题内容: 所以对于这个项目,我试图在运行时扩展一个类。我想知道,这有可能吗?如果是这样,我该怎么办?是否有用于这些目的的库? 问题答案: CGLib是您要查找的库。它在扩展类或在运行时实现接口方面非常强大,因此许多流行的框架(如Spring或Hibernate)都使用它。 您可以使用以下代码创建类扩展 尽管您可能会使用具有所需逻辑的有用的方法拦截器替换回调。

  • 问题内容: 我有能力在编译时扩展一个类,但是我需要能够在运行时使用已实例化的超类的实例创建此子类的实例。 从理论上讲这应该是可能的,因为已经在子类构造函数之前调用了超类构造函数。 我没有足够的程序访问权限来更改实例化到我的子类或中断原始实例化。 用例:现有一个类X实例的数组。我的代码在之后加载。我需要使用已加载的子类Y扩展X来覆盖实例X之一的方法之一。父程序仅通过该数组访问对象,因此我想用Y实例替

  • 只要需要并行的程序逻辑可以划分为不同的职责,并分配给各个独立的step,那么就可以在单个进程中并行执行。并行Step执行很容易配置和使用,例如,将执行步骤(step1,step2)和步骤3step3并行执行,则可以向下面这样配置一个流程: <job id="job1"> <split id="split1" task-executor="taskExecutor" next="step4"

  • 是否可以在测试仍在执行时生成报告。通过潘丁 我的pom.xml是这样的 如果我设置<代码>

  • 很多批处理问题都可以通过单进程、单线程的工作模式来完成, 所以在想要做一个复杂设计和实现之前,请审查你是否真的需要那些超级复杂的实现。 衡量实际作业(job)的性能,看看最简单的实现是否能满足需求: 即便是最普通的硬件,也可以在一分钟内读写上百MB数据文件。 当你准备使用并行处理技术来实现批处理作业时,Spring Batch提供一系列选择,本章将对他们进行讲述,虽然某些功能不在本章中涵盖。从高层

  • 共设5个测试班。每一个都使用@Factory(dataprovider=“data”)初始化。我想实现的是,每个测试类中的测试方法应该与dataprovider实例并行运行。此外,测试类应该并行运行。 如下所示。TestClass1应该并行运行dataprovider实例。因此,测试类TestClass1的所有方法将为dataprovider实例并行运行。 data-provider-thread