001: // $Id: SimpleDDTUnitTest.java 220 2006-03-17 00:22:16Z 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.TestSuite;
041: import junit.textui.TestRunner;
042:
043: /**
044: * Test class to verify simple execution of JUnit TestCase like asserts.
045: *
046: * @author jg
047: *
048: */
049: public class SimpleDDTUnitTest extends DDTTestCase {
050: /**
051: * @param name
052: */
053: public SimpleDDTUnitTest(String name) {
054: super (name);
055: }
056:
057: /**
058: * initialize testmethod environment before every execution
059: */
060: public void setUp() {
061: }
062:
063: /**
064: * Define tests to run
065: *
066: * @return
067: */
068: public static Test suite() {
069: TestSuite ts = new TestSuite();
070:
071: ts.addTestSuite(SimpleDDTUnitTest.class);
072:
073: return ts;
074: }
075:
076: /**
077: * Execute simple valid JUnit assert methods
078: */
079: public void testSimpleJUnitAssert() {
080: assertTrue("Should be true", true);
081: assertNull("Should be null", null);
082: assertEquals("Should be equal", "xxx", "xxx");
083: }
084:
085: /**
086: * @see junitx.ddtunit.DDTTestCase#initTestData()
087: */
088: protected void initContext() {
089: initTestData("SimpleDDTUnitTest", "SimpleDDTUnitTest");
090: }
091:
092: /**
093: * Test retrieving object on a per method-test basis
094: */
095: public void testRetrieveObjectData() {
096: String obj = (String) getObject("myObj");
097:
098: assertNotNull("Method-Test object should not be null", obj);
099: assertTrue("Wrong value for retrieved object", obj
100: .startsWith("My "));
101: }
102:
103: /**
104: * Test retrieving object on a per method-test basis
105: */
106: public void testRetrieveAssertData() {
107: String obj = (String) getObject("myObj");
108:
109: assertNotNull("Method-Test object should not be null", obj);
110: assertTrue("Wrong value for retrieved object", obj
111: .startsWith("My "));
112: addObjectToAssert("result", obj);
113: }
114:
115: /**
116: * Execute TestCase using a JUnit TestRunner.
117: *
118: * @param args
119: */
120: public static void main(String[] args) {
121: TestRunner.run(SimpleDDTUnitTest.suite());
122: }
123: }
|