如何使用 Java 代码刷新文件夹



我想做什么:

测试

执行完成后生成测试报告,然后通过电子邮件发送(我正在使用Maven,Cucumber和RestAssured(。

我面临的问题:

上面提到的一切都在发生,除了通过电子邮件发送的测试报告实际上是来自以前的测试执行。也就是说,当通过电子邮件发送报表的代码运行时,报表或包含报表的文件夹不会刷新。

有没有办法在测试执行结束时通过 maven 刷新文件夹,或者是否有任何其他方法可以发送最新的测试报告..?

任何指针都非常感谢。下面是我的黄瓜运行器代码,

@RunWith(Cucumber.class)
@CucumberOptions(
    features = "src/test/resources/Feature"
    ,glue= "com/sss/tests/RestApi"
    ,tags = {"@TestInDevelopment"}
    ,plugin = {"com.cucumber.listener.ExtentCucumberFormatter:/Report.html"}        
    ,format = {"pretty","html:target/cucumber"}
    ,monochrome = true
    )
public class TestRunner { 
static Configurations config = new Configurations();
@BeforeClass
public static void setup(){
    /*
     * Loading the log4j configurations, before the start of test execution
     */     
    String folderName = "PropertyFiles";
    String fileName = "log4j.properties";
    PropertyConfigurator.configure(config.getResourcePath(folderName)+fileName);
}
@AfterClass
public static void teardown() throws UnknownHostException, IOException, InterruptedException {
    /*
     * Loading the configuration file for the test execution report and setting up the user name, OS info and host details in the report
     */     
    Reporter.loadXMLConfig(new File(config.getResourcePath("Resources")+"extent-config.xml"));
    Reporter.setSystemInfo("USER", System.getProperty("user.name"));
    Reporter.setSystemInfo("OS", System.getProperty("os.name"));
    Reporter.setSystemInfo("HOST NAME", InetAddress.getLocalHost().getHostName());  
   /*
    * After the test execution is completed, parsing the generated test execution report to to see if there is any failures and based on that,
    * sending the Build Success/Failure e-mail to the configured mail list
    */        
    HTML_TestExecutionReportParser testExecutionStatusParser = new HTML_TestExecutionReportParser();    
    TestExecutionReportEmailSender testExecutionReportMailSender = new TestExecutionReportEmailSender();        
    testExecutionReportMailSender.sendTestExecutionReportEmail(testExecutionStatusParser.isAssertionFailureFound(), testExecutionStatusParser.errorsFoundList());     
}

}

您可以尝试将电子邮件代码放在JVM shutdown hook中。因此,当所有其他进程都完成时,将调用它。

关机挂钩示例 -- https://www.geeksforgeeks.org/jvm-shutdown-hook-java/

最新更新