Example 2

Run the test suites org.example.MyTestSuite1 and org.example.MyTestSuite2 and use a JUnit4TestSuiteReporter to generate a test report.

Groovy

// enableTaskPackage org.junit.junit4 import org.entityfs.util.* import org.schmant.run.TaskExecutor import org.schmant.support.io.TempFileUtil import org.schmant.task.junit4.* import org.schmant.task.junit4.suitereporter.JUnit4TestSuiteReporter // Create a JUnit4TestSuiteReporter tsReporter = new JUnit4TestSuiteReporter(). // Use a temporary directory for the report files. setTarget(TempFileUtil.createTempDir()). // Prefix all generated XML files with "myTests" setXmlFilePrefix("myTests") // Use a TaskExecutor to run the test suites in parallel. te = new TaskExecutor().setNumberOfThreads(2).start() try { te.add( new JUnit4TF(). // Enable Java assertions when running the tests setAssertions(true). addTestClass("org.example.MyTestSuite1"). addClasspathEntry(Directories.getFile(lib, "program.jar")). addClasspathEntry(Directories.getFile(lib, "test.jar")). addReporter(JUnit4SimpleReporter.INSTANCE). addReporter(tsReporter)) te.add( new JUnit4TF(). setAssertions(true). addTestClass("org.example.MyTestSuite2"). addClasspathEntry(Directories.getFile(lib, "program.jar")). addClasspathEntry(Directories.getFile(lib, "test.jar")). addReporter(JUnit4SimpleReporter.INSTANCE). // Use the same reporter instance as the previous task. addReporter(tsReporter)) te.waitFor() } finally { te.shutdown() } // Now, after te.waitFor(), both testing tasks have executed and we can create // a report // Create a report that prints to the current thread's Report. // (I.e. to standard out if not configured otherwise.) tsReporter.printReport(); // Create a report that prints to a file // fr = new FileReport(null, new File("unit_test.log")) // try // { // tsReporter.printReport(fr); // } // finally // { // fr.close(); // }

JavaScript

enableTaskPackage("org.junit.junit4"); // Create a JUnit4TestSuiteReporter tsReporter = new JUnit4TestSuiteReporter(). // Use a temporary directory for the report files. setTarget(TempFileUtil.createTempDir()). // Prefix all generated XML files with "myTests" setXmlFilePrefix("myTests"); // Use a TaskExecutor to run the test suites in parallel. te = new TaskExecutor().setNumberOfThreads(2).start(); try { te.add( new JUnit4TF(). // Enable Java assertions when running the tests setAssertions(true). addTestClass("org.example.MyTestSuite1"). addClasspathEntry(Directories.getFile(lib, "program.jar")). addClasspathEntry(Directories.getFile(lib, "test.jar")). addReporter(JUnit4SimpleReporter.INSTANCE). addReporter(tsReporter)); te.add( new JUnit4TF(). setAssertions(true). addTestClass("org.example.MyTestSuite2"). addClasspathEntry(Directories.getFile(lib, "program.jar")). addClasspathEntry(Directories.getFile(lib, "test.jar")). addReporter(JUnit4SimpleReporter.INSTANCE). // Use the same reporter instance as the previous task. addReporter(tsReporter)); te.waitFor(); } finally { te.shutdown(); } // Now, after te.waitFor(), both testing tasks have executed and we can create // a report // Create a report that prints to the current thread's Report. // (I.e. to standard out if not configured otherwise.) tsReporter.printReport(); // Create a report that prints to a file // fr = new FileReport(null, new File("unit_test.log")); // try // { // tsReporter.printReport(fr); // } // finally // { // fr.close(); // }

JRuby

enableTaskPackage "org.junit.junit4" # Create a JUnit4TestSuiteReporter tsReporter = Schmant::JUnit4TestSuiteReporter.new. # Use a temporary directory for the report files. setTarget(Schmant::TempFileUtil.createTempDir). # Prefix all generated XML files with "myTests" setXmlFilePrefix("myTests") # Use a TaskExecutor to run the test suites in parallel. te = Schmant::TaskExecutor.new.setNumberOfThreads(2).start begin te.add( Schmant::JUnit4TF.new. # Enable Java assertions when running the tests setAssertions(true). addTestClass("org.example.MyTestSuite1"). addClasspathEntry(Schmant::Directories.getFile($lib, "program.jar")). addClasspathEntry(Schmant::Directories.getFile($lib, "test.jar")). addReporter(Schmant::JUnit4SimpleReporter::INSTANCE). addReporter(tsReporter)) te.add( Schmant::JUnit4TF.new. setAssertions(true). addTestClass("org.example.MyTestSuite2"). addClasspathEntry(Schmant::Directories.getFile($lib, "program.jar")). addClasspathEntry(Schmant::Directories.getFile($lib, "test.jar")). addReporter(Schmant::JUnit4SimpleReporter::INSTANCE). # Use the same reporter instance. addReporter(tsReporter)) te.waitFor ensure te.shutdown end # Now, after te.waitFor, both testing tasks have executed and we can create # a report # Create a report that prints to the current thread's Report. # (I.e. to standard out if not configured otherwise.) tsReporter.printReport # Create a report that prints to a file # fr = Schmant::FileReport.new(null, Schmant::File.new("unit_test.log")) # begin # tsReporter.printReport fr # # ensure # fr.close

Jython

enableTaskPackage("org.junit.junit4") # Create a JUnit4TestSuiteReporter tsReporter = JUnit4TestSuiteReporter() # Use a temporary directory for the report files. tsReporter.setTarget(org.schmant.support.io.TempFileUtil.createTempDir()) # Prefix all generated XML files with "myTests" tsReporter.setXmlFilePrefix("myTests") # Use a TaskExecutor to run the test suites in parallel. te = TaskExecutor().setNumberOfThreads(2).start() try: # Enable Java assertions when running the test te.add( JUnit4TF(). \ setAssertions(True). \ addTestClass("org.example.MyTestSuite1"). \ addClasspathEntry(Directories.getFile(lib, "program.jar")). \ addClasspathEntry(Directories.getFile(lib, "test.jar")). \ addReporter(JUnit4SimpleReporter.INSTANCE). \ addReporter(tsReporter)) # Use the same reporter instance te.add( JUnit4TF(). \ setAssertions(True). \ addTestClass("org.example.MyTestSuite2"). \ addClasspathEntry(Directories.getFile(lib, "program.jar")). \ addClasspathEntry(Directories.getFile(lib, "test.jar")). \ addReporter(JUnit4SimpleReporter.INSTANCE). \ addReporter(tsReporter)) te.waitFor() finally: te.shutdown() # Now, after te.waitFor(), both testing tasks have executed and we can create a # report. # Create a report that prints to the current thread's Report. # (I.e. to standard out if not configured otherwise.) tsReporter.printReport() # Create a report that prints to a file # fr = FileReport(null, new File("unit_test.log")) # try: # tsReporter.printReport(fr) # # finally: # fr.close()


* That a task is not EntityFS-aware means that it is not aware of DirectoryView filters (it uses them as plain Directory:s) and also that it usually requires that the entities it takes as arguments are in a File-based file file system. (That they are ECFileResolvable.) A non File-resolvable entity can be made so by using the SchmantFileSystems.makeFileResolvable(org.entityfs.EFile) method.