View Javadoc

1   // $Id: SimpleDDTUnitTest.java 220 2006-03-17 00:22:16Z jg_hamburg $
2   /********************************************************************************
3    * DDTUnit, a Datadriven Approach to Unit- and Moduletesting
4    * Copyright (c) 2004, Joerg and Kai Gellien
5    * All rights reserved.
6    *
7    * The Software is provided under the terms of the Common Public License 1.0
8    * as provided with the distribution of DDTUnit in the file cpl-v10.html.
9    * Redistribution and use in source and binary forms, with or without
10   * modification, are permitted provided that the following conditions
11   * are met:
12   *
13   *     + Redistributions of source code must retain the above copyright
14   *       notice, this list of conditions and the following disclaimer.
15   *
16   *     + Redistributions in binary form must reproduce the above
17   *       copyright notice, this list of conditions and the following
18   *       disclaimer in the documentation and/or other materials provided
19   *       with the distribution.
20   *
21   *     + Neither the name of the authors or DDTUnit, nor the
22   *       names of its contributors may be used to endorse or promote
23   *       products derived from this software without specific prior
24   *       written permission.
25   *
26   * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
27   * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
28   * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
29   * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR
30   * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
31   * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
32   * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
33   * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
34   * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
35   * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
36   * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37   ********************************************************************************/
38  package junitx.ddtunit.optional.junit4;
39  
40  import junit.framework.Test;
41  import junit.framework.TestSuite;
42  import junitx.ddtunit.DDTTestCase;
43  import junitx.ddtunit.optional.junit4.DDTUnit4ClassRunner;
44  
45  import org.junit.After;
46  import org.junit.AfterClass;
47  import org.junit.Before;
48  import org.junit.BeforeClass;
49  import org.junit.runner.RunWith;
50  import org.slf4j.Logger;
51  import org.slf4j.LoggerFactory;
52  
53  /**
54   * Test class to verify simple execution of JUnit TestCase like asserts.
55   * 
56   * @author jg
57   * 
58   */
59  @RunWith(value = DDTUnit4ClassRunner.class)
60  public class DDTJUnit4ClassRunnerTest extends DDTTestCase {
61  	final static Logger logger = LoggerFactory.getLogger(DDTJUnit4ClassRunnerTest.class);
62  	
63  	@Before
64  	public void before(){
65  		logger.info("before");
66  	}
67  	
68  	@After
69  	public void after(){
70  		logger.info("after");		
71  	}
72  	
73  	@BeforeClass
74  	public static void beforeClass() {
75  		logger.info("beforeClass");		
76  	}
77  
78  	@AfterClass
79  	public static void afterClass() {
80  		logger.info("afterClass");		
81  	}
82  	
83  	protected void setUp() throws Exception {
84  		logger.info("setUp()");
85  	}
86  	
87  	protected void tearDown() throws Exception {
88  		logger.info("tearDown()");
89  	}
90  	
91  	/**
92       * @param name
93       */
94      public DDTJUnit4ClassRunnerTest(String name) {
95          super(name);
96      }
97      
98      
99      public DDTJUnit4ClassRunnerTest() {
100     	
101     }
102 
103     /**
104      * Define tests to run
105      * 
106      * @return
107      */
108     public static Test suite() {
109         TestSuite ts = new TestSuite();
110 
111         ts.addTestSuite(DDTJUnit4ClassRunnerTest.class);
112 
113         return ts;
114     }
115 
116     /**
117      * Execute simple valid JUnit assert methods
118      */
119     @org.junit.Test
120     public void simpleJUnitAssert() {
121     	logger.info("simpleJUnitAssert");
122         assertTrue("Should be true", true);
123         assertNull("Should be null", null);
124         assertEquals("Should be equal", "xxx", "xxx");
125     }
126 
127     /**
128      * @see junitx.ddtunit.DDTTestCase#initTestData()
129      */
130     public void initContext() {
131         initTestData("DDTJUnit4ClassRunnerTest");
132     }
133 
134     /**
135      * Test retrieving object on a per method-test basis
136      */
137     @org.junit.Test   
138     public void retrieveObjectData() {
139     	logger.info("retrieveObjectData");
140         String obj = (String) getObject("myObj");
141 
142         assertNotNull("Method-Test object should not be null", obj);
143         assertTrue("Wrong value for retrieved object", obj.startsWith("My "));
144     }
145 
146     /**
147      * Test retrieving object on a per method-test basis
148      */  
149     public void retrieveAssertData() {
150         String obj = (String) getObject("myObj");
151         fail();
152         assertNotNull("Method-Test object should not be null", obj);
153         assertTrue("Wrong value for retrieved object", obj.startsWith("My "));
154         addObjectToAssert("result", obj);
155     }
156 
157 }