001: //$Id: DDTRunMonitorTest.java 280 2007-07-19 21:54:00Z jg_hamburg $
002: /********************************************************************************
003: * DDTUnit, a Datadriven Approach to Unit- and Moduletesting
004: * Copyright (c) 2004, Joerg and Kai Gellien
005: * All rights reserved.
006: *
007: * The Software is provided under the terms of the Common Public License 1.0
008: * as provided with the distribution of DDTUnit in the file cpl-v10.html.
009: * Redistribution and use in source and binary forms, with or without
010: * modification, are permitted provided that the following conditions
011: * are met:
012: *
013: * + Redistributions of source code must retain the above copyright
014: * notice, this list of conditions and the following disclaimer.
015: *
016: * + Redistributions in binary form must reproduce the above
017: * copyright notice, this list of conditions and the following
018: * disclaimer in the documentation and/or other materials provided
019: * with the distribution.
020: *
021: * + Neither the name of the authors or DDTUnit, nor the
022: * names of its contributors may be used to endorse or promote
023: * products derived from this software without specific prior
024: * written permission.
025: *
026: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
027: * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
028: * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
029: * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR
030: * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
031: * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
032: * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
033: * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
034: * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
035: * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
036: * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
037: ********************************************************************************/package junitx.ddtunit;
038:
039: import junit.framework.Test;
040: import junit.framework.TestCase;
041: import junit.framework.TestResult;
042: import junit.framework.TestSuite;
043: import junit.textui.TestRunner;
044: import junitx.ddtunit.report.DDTTextTestRunner;
045:
046: public class DDTRunMonitorTest extends TestCase {
047:
048: private static DDTRunMonitor monitor;
049:
050: protected void setUp() throws Exception {
051: monitor = DDTRunMonitor.getInstance();
052: }
053:
054: public void testRunStandardTestCase() throws Exception {
055: TestResult result = TestRunner.run(MyTest.suite());
056: assertEquals("Wrong number of testmethods", 2, result
057: .runCount());
058: assertEquals("Wrong number of errors", 1, result.errorCount());
059: assertEquals("Wrong number of failures", 0, result
060: .failureCount());
061: }
062:
063: public void testRunDDTTestCase() {
064: TestRunner runner = new DDTTextTestRunner();
065: runner.setPrinter(DDTRunMonitor.getInstance());
066: DDTTestResult result = (DDTTestResult) runner.doRun(MyDDTTest
067: .suite());
068: assertEquals("Wrong number of testmethods", 2, result
069: .runCount());
070: assertEquals("Wrong number of total testcases", 5, result
071: .runMethodTestCount());
072: assertEquals("Wrong number of errors", 0, result.errorCount());
073: assertEquals("Wrong number of failures", 2, result
074: .failureCount());
075: assertEquals(
076: "Wrong number of failures of testcases per methods", 3,
077: result.methodTestFailureCount());
078: }
079:
080: public static class MyTest extends TestCase {
081: public MyTest(String name) {
082: super (name);
083: }
084:
085: public static Test suite() {
086: return new TestSuite(MyTest.class);
087: }
088:
089: protected void setUp() throws Exception {
090: monitor = DDTRunMonitor.getInstance();
091: }
092:
093: public void testCorrectMethod() throws Exception {
094: assertTrue("Should allways be true", true);
095: }
096:
097: public void testWrongMethod() throws Exception {
098: throw new RuntimeException("Test failed expectedly");
099: }
100: }
101:
102: public static class MyDDTTest extends DDTTestCase {
103: public MyDDTTest(String name) {
104: super (name);
105: }
106:
107: public static Test suite() {
108: return new TestSuite(MyDDTTest.class);
109: }
110:
111: protected void setUp() throws Exception {
112: monitor = DDTRunMonitor.getInstance();
113: }
114:
115: public void testZCorrectMethod() throws Exception {
116: addObjectToAssert("result", getObject("myObj"));
117: }
118:
119: public void testWrongMethod() throws Exception {
120: fail("Should allways fail");
121: }
122:
123: protected void initContext() {
124: initTestData("DDTRunMonitorTest", "DDTRunMonitorTest");
125: }
126: }
127:
128: public void testGetInstance() {
129: DDTRunMonitor monitor = DDTRunMonitor.getInstance();
130: assertNotNull(monitor);
131: assertSame("There should be a singleton", monitor,
132: DDTRunMonitor.getInstance());
133: }
134: }
|