Source Code Cross Referenced for ExecutionResultTest.java in  » Testing » DDTUnit » junitx » ddtunit » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Testing » DDTUnit » junitx.ddtunit 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        // $Id: ExecutionResultTest.java 326 2007-09-21 18:43:13Z 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.TestCase;
040:        import junit.framework.TestFailure;
041:        import junitx.ddtunit.resources.RunnerMonitor;
042:
043:        /**
044:         * Test different execution runs with different DDTTestResults.
045:         * 
046:         * @author jg
047:         */
048:        public class ExecutionResultTest extends TestCase {
049:            private static final String LF = System
050:                    .getProperty("line.separator");
051:
052:            private DDTTestResult result;
053:
054:            private String testResource;
055:
056:            private String classId;
057:
058:            /**
059:             * Constructor of ExecutionResultTest
060:             * 
061:             * @param name
062:             */
063:            public ExecutionResultTest(String name) {
064:                super (name);
065:            }
066:
067:            /**
068:             * Setup test environment
069:             * 
070:             * @see junit.framework.TestCase#setUp()
071:             */
072:            public void setUp() {
073:                result = new DDTTestResult();
074:                result.addListener(RunnerMonitor.getInstance());
075:            }
076:
077:            /**
078:             * Execute internal DDTTestCase with one method and three xml based tests,
079:             * no execution exception.
080:             * 
081:             */
082:            public void testRunThreeMethodTestsNoProblem() {
083:                this .testResource = "ExecutionResultTest";
084:                this .classId = "ExecutionResultNoProblem";
085:
086:                String testMethod = "testThreeTestsNoProblem";
087:                DDTExecutionTest test = new DDTExecutionTest(testMethod);
088:
089:                test.run(result);
090:                assertEquals("Wrong number of methods executed", 1, result
091:                        .runCount());
092:                assertEquals("No failures expected", 0, result.failureCount());
093:                assertEquals("No errors expected", 0, result.errorCount());
094:
095:                //
096:                assertEquals("Wrong number of method tests.", 3, result
097:                        .runMethodTestCount());
098:                assertEquals("No failures in method test execution expected.",
099:                        0, result.methodTestFailureCount());
100:                assertEquals("No errors in method test execution expected.", 0,
101:                        result.methodTestErrorCount());
102:            }
103:
104:            /**
105:             * Execute internal DDTTestCase with one method and three xml based tests,
106:             * one AssertionFailed exception.
107:             * 
108:             */
109:            public void testRunThreeMethodTestsOneAssertFailedException() {
110:                this .testResource = "ExecutionResultTest";
111:                this .classId = "ExecutionResultNoProblem";
112:
113:                String testMethod = "testThreeTestsOneAssertFailed";
114:                DDTExecutionTest test = new DDTExecutionTest(testMethod);
115:
116:                test.run(result);
117:                assertEquals("Wrong number of methods executed", 1, result
118:                        .runCount());
119:                assertEquals("No errors expected", 0, result.errorCount());
120:                assertEquals("One failures expected", 1, result.failureCount());
121:
122:                // check returned failure message
123:                String message = ((TestFailure) result.failures().nextElement())
124:                        .exceptionMessage();
125:                String expected = "method testThreeTestsOneAssertFailed - Total: 3, Errors: 0, Failures: 1"
126:                        + LF
127:                        + "F-(my-second-testcase) Wrong isEqual assert on (multiline) string [position 0] expected:<my-unexpected-testcase> but was:<my-second-testcase>";
128:                assertEquals("Wrong exepction message in JUnit failure",
129:                        expected, message);
130:                assertEquals("Wrong number of method tests.", 3, result
131:                        .runMethodTestCount());
132:                assertEquals("No errors in method test execution expected.", 0,
133:                        result.methodTestErrorCount());
134:                assertEquals("One failures in method test execution expected.",
135:                        1, result.methodTestFailureCount());
136:                message = ((TestFailure) result.methodTestFailures().next())
137:                        .exceptionMessage();
138:                expected = "Wrong isEqual assert on (multiline) string [position 0] "
139:                        + "expected:<my-unexpected-testcase> but was:<my-second-testcase>";
140:                assertEquals("Wrong exception message of method test failure",
141:                        expected, message);
142:            }
143:
144:            /**
145:             * Execute internal DDTTestCase with one method and three xml based tests,
146:             * one AssertionFailed and one other exception.
147:             * 
148:             */
149:            public void testRunThreeMethodTestsOneAssertFailedOneException() {
150:                this .testResource = "ExecutionResultTest";
151:                this .classId = "ExecutionResultNoProblem";
152:
153:                String testMethod = "testThreeTestsOneAssertFailedOneException";
154:                DDTExecutionTest test = new DDTExecutionTest(testMethod);
155:
156:                test.run(result);
157:                assertEquals("Wrong number of methods executed", 1, result
158:                        .runCount());
159:                assertEquals("One errors expected", 1, result.errorCount());
160:                assertEquals("One failures expected", 0, result.failureCount());
161:                assertEquals("Wrong number of method tests executed", 3, result
162:                        .runMethodTestCount());
163:                assertEquals("One errors expected", 1, result
164:                        .methodTestErrorCount());
165:                assertEquals("One failures expected", 1, result
166:                        .methodTestFailureCount());
167:
168:                // check returned error message
169:                String message = ((TestFailure) result.errors().nextElement())
170:                        .exceptionMessage();
171:                String expected = "method testThreeTestsOneAssertFailedOneException - "
172:                        + "Total: 3, Errors: 1, Failures: 1"
173:                        + LF
174:                        + "E-(my-first-testcase) Throw expected exception"
175:                        + LF
176:                        + "F-(my-second-testcase) Wrong isEqual assert on (multiline) "
177:                        + "string [position 0] expected:<my-unexpected-testcase> but was:"
178:                        + "<my-second-testcase>";
179:                assertEquals("Wrong exception message in JUnit failure",
180:                        expected, message);
181:                assertEquals("One failures in method test execution expected.",
182:                        1, result.methodTestFailureCount());
183:                message = (result.methodTestFailures().next())
184:                        .exceptionMessage();
185:                expected = "Wrong isEqual assert on (multiline) string [position 0]"
186:                        + " expected:<my-unexpected-testcase> but was:<my-second-testcase>";
187:                assertEquals("Wrong exception message of method test failure",
188:                        expected, message);
189:            }
190:
191:            /**
192:             * Internal DDTTestCase class for starting test execution. <br/>XML test
193:             * resource and classId are parametrised using outer class fields.
194:             * 
195:             * @author jg
196:             */
197:            private class DDTExecutionTest extends DDTTestCase {
198:                /**
199:                 * Instanciate DDTTestCase with method name to execute
200:                 * 
201:                 * @param name
202:                 */
203:                public DDTExecutionTest(String name) {
204:                    super (name);
205:                }
206:
207:                /**
208:                 * @see junitx.ddtunit.DDTTestCase#initTestData()
209:                 */
210:                protected void initContext() {
211:                    initTestData(testResource, classId);
212:                }
213:
214:                /**
215:                 * Run test method with three xml based tests and no exceptions expected
216:                 * during execution.
217:                 */
218:                public void testThreeTestsNoProblem() {
219:                }
220:
221:                /**
222:                 * Run test method with three xml based tests and one assertino
223:                 * exception during execution
224:                 */
225:                public void testThreeTestsOneAssertFailed() {
226:                    addObjectToAssert("result", getObject("objId"));
227:                }
228:
229:                /**
230:                 * Run test method with three xml based tests and one assertion and one
231:                 * other exception during execution
232:                 */
233:                public void testThreeTestsOneAssertFailedOneException() {
234:                    String value = (String) getObject("objId");
235:
236:                    addObjectToAssert("result", value);
237:
238:                    if ("my-first-testcase".equals(value)) {
239:                        throw new DDTException("Throw expected exception");
240:                    }
241:                }
242:            }
243:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.