0
0
JUnittesting~10 mins

XML and HTML reports in JUnit - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete 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'
Awrite
Bsave
Coutput
Dprint
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.
2fill in blank
medium

Complete 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'
Agenerate
Bcreate
Cbuild
Drun
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.
3fill in blank
hard

Fix 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'
AwriteReport
BgenerateReport
CsaveReport
DexportReport
Attempts:
3 left
💡 Hint
Common Mistakes
Using writeReport or saveReport which are not defined methods.
Using exportReport which is not a valid method here.
4fill in blank
hard

Fill 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'
AsetInputFile
BsetSourceFile
CsetOutputDirectory
DsetDestinationFolder
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing input and output methods.
Using setSourceFile or setDestinationFolder which are not standard method names.
5fill in blank
hard

Fill 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'
Arun
Btest-results.xml
Cwrite
Dexecute
Attempts:
3 left
💡 Hint
Common Mistakes
Using execute() instead of run() to run tests.
Using incorrect file names or method names.