Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to generate a JUnit XML report file.
JUnit
JUnitCore junit = new JUnitCore(); Result result = junit.run(MyTestClass.class); File file = new File("test-results.xml"); JUnitResultWriter writer = new JUnitResultWriter(file); writer.[1](result);
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using save() or print() which are not valid methods for JUnitResultWriter.
Trying to call write() without passing the result object.
✗ Incorrect
The JUnitResultWriter uses the write() method to save the test results to an XML file.
2fill in blank
mediumComplete the code to generate an HTML report from JUnit XML results using the ReportGenerator class.
JUnit
ReportGenerator generator = new ReportGenerator(); generator.setInputFile("test-results.xml"); generator.setOutputDirectory("reports"); generator.[1]();
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using create() or run() which do not exist in ReportGenerator.
Forgetting to set input or output paths before calling the method.
✗ Incorrect
The ReportGenerator class uses the generate() method to create the HTML report from XML input.
3fill in blank
hardFix the error in the XML report generation code by completing the missing method call.
JUnit
JUnitCore junit = new JUnitCore(); Result result = junit.run(MyTests.class); JUnitXMLReporter reporter = new JUnitXMLReporter(); reporter.[1](result, new File("results.xml"));
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using writeReport or saveReport which are not defined methods.
Using exportReport which is not a valid method here.
✗ Incorrect
The correct method to generate the XML report is generateReport(), which takes the test result and output file.
4fill in blank
hardFill both blanks to configure the HTML report generator with input XML and output folder.
JUnit
HTMLReportGenerator generator = new HTMLReportGenerator(); generator.[1]("results.xml"); generator.[2]("html-report");
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing input and output methods.
Using setSourceFile or setDestinationFolder which are not standard method names.
✗ Incorrect
Use setInputFile() to specify the XML input and setOutputDirectory() to specify the HTML output folder.
5fill in blank
hardFill all three blanks to create a test suite, run it, and generate an XML report file.
JUnit
TestSuite suite = new TestSuite(); suite.addTestSuite(MyTestClass.class); JUnitCore core = new JUnitCore(); Result result = core.[1](suite); JUnitXMLWriter writer = new JUnitXMLWriter(new File("[2]")); writer.[3](result);
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using execute() instead of run() to run tests.
Using incorrect file names or method names.
✗ Incorrect
Use run() to execute the suite, specify the XML filename as 'test-results.xml', and write() to save the results.