Reputation: 7566
I have set of test methods (@Test) that I can run with a Gradle task and each test has the Allure report generated for it.
But when I run the same tests by building the test XmlSuite dynamically, the tests execute as expected, but the Allure reports don't get generated.
If I annotate the example method as @Test - it will have its Allure report generated, but not the tests it triggers.
Is there a way to trigger the Allure reports for tests executed in this way?
//@Test
public static void guiTestInit() {
// this will read a props file after drag-and-drop and provide data for tests
Application.launch(GatherInputGui.class);
TestNG dynoTest = new TestNG();
XmlSuite suite = new XmlSuite();
suite.setName("Dyno Suite");
XmlTest test = new XmlTest(suite);
test.setName("Dyno Test");
List<XmlClass> classes = new ArrayList<XmlClass>();
XmlClass cl = new XmlClass("tests.MyTestClass");
// Add an arbitrary number of tests/methods to execure
if (getMethods().isEmpty()) {
cl.getIncludedMethods().add(new XmlInclude("defaultTestMethod", 0));
} else {
for (int i = 0; i < getMethods().size(); i++) {
cl.getIncludedMethods().add(new XmlInclude(getMethods().get(i), i));
}
}
classes.add(cl);
test.setXmlClasses(classes);
List<XmlSuite> suites = new ArrayList<XmlSuite>();
suites.add(suite);
dynoTest.setXmlSuites(suites);
//see the generated XML
//System.out.println(suite.toXml());
dynoTest.run();
}
Upvotes: 1
Views: 806
Reputation: 7566
Ended up building a launcher for the allure server. Unfortunately don't recall where I got the pieces for it.
package gui;
import java.io.File;
public class AllureLauncherUtils {
public static void launchAllure(){
try {
String currentDirectory;
File file = new File(".");
currentDirectory = file.getAbsolutePath();
System.out.println("Current working directory : "+currentDirectory);
ProcessBuilder procBuilderGenerateReports = new ProcessBuilder();
ProcessBuilder procBuilderDisplayReports = new ProcessBuilder();
/** write output and errors to log **/
File log = new File("ALLURE-LAUNCHER-LOG.log");
procBuilderGenerateReports.redirectOutput(ProcessBuilder.Redirect.appendTo(log));
procBuilderGenerateReports.redirectError(ProcessBuilder.Redirect.appendTo(log));
procBuilderDisplayReports.redirectOutput(ProcessBuilder.Redirect.appendTo( log ));
procBuilderDisplayReports.redirectError( ProcessBuilder.Redirect.appendTo( log ));
/**
* As part of the installation of the test suite, the Allure server parts reside in a hidden directory '.allure'
* There are two files in the '.allure/allure-2.6.0/bin' directory:
* 'allure' - a UN*X shell script
* and
* 'allure.bat' - windows batch file
* They are used to start the embedded Jetty server (depending on your system) to display the test reports.
* They add allure and jetty jars to the class path and start the server, so it's impractical to try and
* start the allure server in a more granular way
*
**/
/** GENERATE THE REPORTS **/
procBuilderGenerateReports.command( currentDirectory + "\\.allure\\allure-2.6.0\\bin\\allure.bat", "generate", "--clean");
Process processGenerateReports = procBuilderGenerateReports.start();
StreamGobbler generateReportOutputGobbler = new StreamGobbler( processGenerateReports.getInputStream(), "OUTPUT" );
StreamGobbler generateReportErrorGobbler = new StreamGobbler(processGenerateReports.getErrorStream(), "ERROR");
generateReportOutputGobbler.start();
generateReportErrorGobbler.start();
/** START THE SERVER AND DISPLAY THE REPORTS **/
procBuilderDisplayReports.command( currentDirectory + "\\.allure\\allure-2.6.0\\bin\\allure.bat", "serve", currentDirectory + "\\build\\allure-results");
Process processDisplayAllureReports = procBuilderDisplayReports.start();
StreamGobbler displayReportOutputGobbler = new StreamGobbler( processDisplayAllureReports.getInputStream(), "OUTPUT" );
StreamGobbler displayReportErrorGobbler = new StreamGobbler(processDisplayAllureReports.getErrorStream(), "ERROR");
/** capture output and error to console */
displayReportOutputGobbler.start();
displayReportErrorGobbler.start();
//processDisplayAllureReports.destroy();
//processGenerateReports.destroy();
System.exit(0);
} catch (Throwable t) {
t.printStackTrace();
}
}
}
Upvotes: 1