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

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


      {
         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();
View Full Code Here


        if (!quiet)
        {
            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();
View Full Code Here

*/
public class XmlJUnitResultFormatter_setSystemOutput_Test extends XmlJUnitResultFormatter_TestCase {

  @Test
  public void should_add_system_output() {
    formatter.startTestSuite(new JUnitTest("test"));
    formatter.setSystemOutput(CONSOLE_OUTPUT);
    XmlNode systemOutNode = root().child(1);
    assertThat(systemOutNode.name()).isEqualTo("system-out");
    assertThat(systemOutNode.text()).isEqualTo(CONSOLE_OUTPUT);
  }
View Full Code Here

  public void shouldWriterPropertiesAsAttributes() {
    Properties properties = new Properties();
    properties.setProperty("key1", "value1");
    properties.setProperty("key2", "value2");
    final JUnitTest suite = new JUnitTest("Hello");
    suite.setProperties(properties);
    final XmlNode propertiesNode = mockXmlNode();
    new EasyMockTemplate(targetNode, propertiesNode) {
      @Override protected void expectations() throws Exception {
        expect(targetNode.addNewNode(PROPERTIES)).andReturn(propertiesNode);
        XmlAttributes attributes1 = attributes(name(ATTR_NAME).value("key1"), name(ATTR_VALUE).value("value1"));
View Full Code Here

      }
    }.run();
  }

  public void shouldNotAddPropertiesIfPropertiesIsNull() {
    final JUnitTest suite = new JUnitTest("Hello");
    assertThat(suite.getProperties()).isNull();
    final XmlNode propertiesNode = mockXmlNode();
    new EasyMockTemplate(targetNode, propertiesNode) {
      @Override protected void expectations() throws Exception {
        expect(targetNode.addNewNode(PROPERTIES)).andReturn(propertiesNode);
      }
View Full Code Here

      }
    }.run();
  }

  public void shouldNotAddPropertiesIfPropertiesIsEmpty() {
    final JUnitTest suite = new JUnitTest("Hello");
    suite.setProperties(new Properties());
    assertThat(suite.getProperties()).isEmpty();
    final XmlNode propertiesNode = mockXmlNode();
    new EasyMockTemplate(targetNode, propertiesNode) {
      @Override protected void expectations() throws Exception {
        expect(targetNode.addNewNode(PROPERTIES)).andReturn(propertiesNode);
      }
View Full Code Here

  private XmlNode mockXmlNode() {
    return createMock(XmlNode.class);
  }

  public void shouldWriteStatisticsAsAttribute() {
    final JUnitTest suite = new JUnitTest("Hello");
    suite.setCounts(6l, 2l, 1l);
    suite.setRunTime(8000l);
    new EasyMockTemplate(targetNode) {
      @Override protected void expectations() {
        expectAttributeAdded(name(ATTR_TESTS).value(6l));
        expectAttributeAdded(name(ATTR_FAILURES).value(2l));
        expectAttributeAdded(name(ATTR_ERRORS).value(1l));
View Full Code Here

    assertThat(time).isGreaterThanOrEqualTo(0d);
    assertThatSuiteAndEnvironmentInfoWereAddedTo(root);
  }

  private JUnitTest startTestSuiteWithStatistics() {
    JUnitTest s = startSuite();
    s.setCounts(18, 8, 6);
    return s;
  }
View Full Code Here

*/
public class SuiteXmlNodeWriter_writeSuiteName_Test extends SuiteXmlNodeWriter_TestCase {

  @Test
  public void should_write_suite_name_as_attribute() {
    final JUnitTest suite = new JUnitTest("Hello");
    new EasyMockTemplate(targetNode) {
      @Override protected void expectations() throws Exception {
        targetNode.addAttribute(name(ATTR_NAME).value("Hello"));
        expectLastCall().once();
      }
View Full Code Here

    }.run();
  }

  @Test
  public void should_write_word_unknown_as_attribute_if_suite_does_not_have_name() {
    final JUnitTest suite = new JUnitTest(null);
    new EasyMockTemplate(targetNode) {
      @Override protected void expectations() throws Exception {
        targetNode.addAttribute(name(ATTR_NAME).value("unknown"));
      }
View Full Code Here

TOP

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

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.