Package org.apache.tools.ant.taskdefs.optional.junit

Examples of org.apache.tools.ant.taskdefs.optional.junit.XMLJUnitResultFormatter


      try
      {
         TestResult result = new TestResult();

         XMLJUnitResultFormatter resultFormatter = new XMLJUnitResultFormatter();

         JUnitTest dummyJUnit = new JUnitTest(name);
         resultFormatter.startTestSuite(dummyJUnit);

         OutputStream writer = new FileOutputStream(new File(reportFile));
         resultFormatter.setOutput(writer);

         result.addListener(resultFormatter);

         TestSuite suite = new TestSuite();

        
         JUnitClientTest test = null;
         try
         {
            test = (JUnitClientTest) Class.forName(testClass).newInstance();
         }
         catch (ClassCastException e)
         {
            System.err.println("Class " + testClass + " does not implement " + JUnitClientTest.class.getName());
         }
         catch (ClassNotFoundException e)
         {
            System.err.println("Cannot locate class " + testClass);
         }
         catch (IllegalAccessException e)
         {
            e.printStackTrace();
         }
         catch (InstantiationException e)
         {
            System.err.println("Class " + testClass + " cannot be instantiated: " + e.getMessage());
         }

         test.setName("testAction");
         test.init(config, params, isDebug);

         suite.addTest(test);

         long startTime = new Date().getTime();
         suite.run(result);
         long endTime = new Date().getTime();
        
         dummyJUnit.setCounts(result.runCount(), result.failureCount(), result.errorCount());
         dummyJUnit.setRunTime(endTime - startTime);
        
         resultFormatter.endTestSuite(dummyJUnit);

         writer.close();

         return result.wasSuccessful();
      }
View Full Code Here


            result.addListener(new PrintListener());
        }

        JUnitTest antTest = null;
        FileOutputStream fout = null;
        XMLJUnitResultFormatter formatter = null;

        if (dir != null)
        {
            antTest = new JUnitTest(test.getName(), false, false, true);

            formatter = new XMLJUnitResultFormatter();
            formatter.startTestSuite(antTest);

            String name = "TEST-" + test.getName() + ".xml";

            File f = new File(dir, name);
            fout = new FileOutputStream(f);
            formatter.setOutput(fout);
            result.addListener(formatter);
        }
       
        test.run(result);

        System.out.flush();
        System.err.flush();

        if ( dir != null ) {
            formatter.setSystemOutput( tempOut.toString() );
            formatter.setSystemError( tempErr.toString() );
           
            antTest.setCounts(result.runCount(), result.failureCount(),
                result.errorCount());
           
            formatter.endTestSuite(antTest);
           
            fout.flush();
            fout.close();
        }                       
    }
View Full Code Here

   *
   */
  public AutoTestRunner(JUnitTest test, String testPluginName, AutoTestSuite autoTestSuite, File outputDirectory) {
    fJunitTest = test;
    fSuite = autoTestSuite;
    formatter = new XMLJUnitResultFormatter();
    File file = new File( outputDirectory, testPluginName + ".xml" );
    try {
      formatter.setOutput( new FileOutputStream( file ) );
    } catch (FileNotFoundException e) {
      // TODO Auto-generated catch block
View Full Code Here

    final JUnitTest jUnitTest = new JUnitTest("ch.ethz.iks.slp.test");
      jUnitTest.setProperties(System.getProperties());
     
      // create the xml result formatter
    final JUnitResultFormatter xmlResultFormatter = new XMLJUnitResultFormatter();
    final File file = new File(outputDirectory, "TEST-ch.ethz.iks.slp.test" + ".xml");
    try {
      xmlResultFormatter.setOutput(new FileOutputStream(file));
    } catch (FileNotFoundException e) {
      // may never happen
      e.printStackTrace();
    }
    result.addListener(xmlResultFormatter);
    // create a result formatter that prints to the console
    final JUnitResultFormatter consoleResultFormatter = new BriefJUnitResultFormatter();
    consoleResultFormatter.setOutput(System.out);
    result.addListener(consoleResultFormatter);

    // add the actual tests to the test suite
    Collection collection = new ArrayList();
    collection.add(SelfDiscoveryTest.class);
    for (Iterator iterator = collection.iterator(); iterator.hasNext();) {
      Class clazz = (Class) iterator.next();
      // run all methods starting with "test*"
      Method[] methods = clazz.getMethods();
      for (int i = 0; i < methods.length; i++) {
        if (methods[i].getName().startsWith("test")) {
          TestCase testCase;
          try {
            testCase = (TestCase) clazz.newInstance();
            testCase.setName(methods[i].getName());
            suite.addTest(testCase);
          } catch (InstantiationException e) {
            // may never happen
            e.printStackTrace();
          } catch (IllegalAccessException e) {
            // may never happen
            e.printStackTrace();
          }
        }
      }
    }
   
    // prepare to run tests
    final long start = System.currentTimeMillis();
    xmlResultFormatter.startTestSuite(jUnitTest);
    consoleResultFormatter.startTestSuite(jUnitTest);
   
      // run tests
    suite.run(result);
     
    // write stats and close reultformatter
    jUnitTest.setCounts(result.runCount(), result.failureCount(), result.errorCount());
      jUnitTest.setRunTime(System.currentTimeMillis() - start);
    xmlResultFormatter.endTestSuite(jUnitTest);
    consoleResultFormatter.endTestSuite(jUnitTest);
   
    // print success of failure
    if (result.wasSuccessful()) {
      System.exit(0);
View Full Code Here

TOP

Related Classes of org.apache.tools.ant.taskdefs.optional.junit.XMLJUnitResultFormatter

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.