@Test在TestNG中不起作用

时间:2018-02-10 21:41:32

标签: selenium selenium-webdriver

我正在使用TestNG进行报告,但是当我尝试创建一个测试方法时,eclipse会显示以下消息:语法错误,插入&#34 ;;"完成LocalVariableDeclarationStatement。 日食会提示您在方法括号的末尾插入分号。

public class ExtentReports3 {

ExtentHtmlReporter htmlReporter;
ExtentReports extent;
ExtentTest test;

@BeforeTest
public void startReport() {

    htmlReporter = new ExtentHtmlReporter(System.getProperty("user.dir")+"/test-output/MyOwnReport.html");
    extent = new ExtentReports();
    extent.attachReporter(htmlReporter);

    extent.setSystemInfo("Sistema Operacional", "Windows 10");
    extent.setSystemInfo("Host Name", "");
    extent.setSystemInfo("Enviromment", "QA");
    extent.setSystemInfo("User Name", "Leandro Pereira");

    htmlReporter.config().setDocumentTitle("AutomationTesting.in Demo Report");
    htmlReporter.config().setReportName("My Own Report");
    htmlReporter.config().setTestViewChartLocation(ChartLocation.TOP);
    htmlReporter.config().setTheme(Theme.DARK);

    @Test
    public  void demoTestPass() {   
            test = extent.createTest("demoTestPass","This test will demostrate the PASS test case");
            Assert.assertTrue(true);
    }

Image erro

Image erro 2

1 个答案:

答案 0 :(得分:0)

您无法在@Test@BeforeTest更正您的代码......例如。

public class ExtentReports3 {

ExtentHtmlReporter htmlReporter;
ExtentReports extent;
ExtentTest test;

@BeforeTest
public void startReport() {

    htmlReporter = new ExtentHtmlReporter(System.getProperty("user.dir")+"/test-output/MyOwnReport.html");
    extent = new ExtentReports();
    extent.attachReporter(htmlReporter);

    extent.setSystemInfo("Sistema Operacional", "Windows 10");
    extent.setSystemInfo("Host Name", "");
    extent.setSystemInfo("Enviromment", "QA");
    extent.setSystemInfo("User Name", "Leandro Pereira");

    htmlReporter.config().setDocumentTitle("AutomationTesting.in Demo Report");
    htmlReporter.config().setReportName("My Own Report");
    htmlReporter.config().setTestViewChartLocation(ChartLocation.TOP);
    htmlReporter.config().setTheme(Theme.DARK);
}
    @Test
    public void demoTestPass() {   
            test = extent.createTest("demoTestPass","This test will demostrate the PASS test case");
            Assert.assertTrue(true);
    }
相关问题