Source Code Cross Referenced for TestFor.java in  » Test-Coverage » Hansel » org » hanseltest » 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 » Test Coverage » Hansel » org.hanseltest 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package org.hanseltest;
002:
003:        import junit.framework.TestCase;
004:        import junit.framework.TestResult;
005:
006:        import org.hansel.CoverageDecorator;
007:
008:        /**
009:         * Test the coverage test of for statements. 
010:         * 
011:         * @author Niklas Mehner
012:         */
013:        public class TestFor extends TestCase {
014:            /** Class the tests cover. */
015:            private static final Class[] COVERED = { CoverFor.class };
016:
017:            /**
018:             * Create a new test.
019:             * @param name Name of the test.
020:             */
021:            public TestFor(String name) {
022:                super (name);
023:            }
024:
025:            /**
026:             * No code is covered.
027:             */
028:            public void testNoCoverage() {
029:                CoverageDecorator cd = new CoverageDecorator(NoCoverage.class,
030:                        COVERED);
031:
032:                TestResult result = new TestResult();
033:
034:                cd.run(result);
035:
036:                // 3 Failures: 2 Methods and 1 Constructor
037:                assertEquals(3, result.failureCount());
038:
039:                // No errors
040:                assertEquals(0, result.errorCount());
041:            }
042:
043:            /**
044:             * Only a part of the class is covered.
045:             * See inner class PartCoverage1 for more detail.
046:             */
047:            public void testPartCoverage1() {
048:                CoverageDecorator cd = new CoverageDecorator(
049:                        PartCoverage1.class, COVERED);
050:
051:                TestResult result = new TestResult();
052:
053:                cd.run(result);
054:
055:                // One failures: The second method is not covered. 
056:                assertEquals(1, result.failureCount());
057:
058:                // No errors
059:                assertEquals(0, result.errorCount());
060:            }
061:
062:            /**
063:             * Only a part of the class is covered.
064:             * See inner class PartCoverage2 for more detail.
065:             */
066:            public void testPartCoverage2() {
067:                CoverageDecorator cd = new CoverageDecorator(
068:                        PartCoverage2.class, COVERED);
069:
070:                TestResult result = new TestResult();
071:
072:                cd.run(result);
073:
074:                // Only the expression in expressionFor() is not fully covered.
075:                //org.hansel.Util.dumpResult(result);
076:                assertEquals(1, result.failureCount());
077:
078:                // No errors
079:                assertEquals(0, result.errorCount());
080:            }
081:
082:            /**
083:             * Test full coverage of the class.
084:             */
085:            public void testFullCoverage() {
086:                CoverageDecorator cd = new CoverageDecorator(
087:                        FullCoverage.class, COVERED);
088:
089:                TestResult result = new TestResult();
090:
091:                cd.run(result);
092:
093:                // No failures
094:                assertEquals(0, result.failureCount());
095:
096:                // No errors
097:                assertEquals(0, result.errorCount());
098:            }
099:
100:            /**
101:             * TestCase does covers no code at all.
102:             */
103:            public static class NoCoverage extends TestCase {
104:                /**
105:                 * Creates a new test.
106:                 * @param name Name of the test.
107:                 */
108:                public NoCoverage(String name) {
109:                    super (name);
110:                }
111:
112:                /** Empty method. */
113:                public void testNothing() {
114:                }
115:            }
116:
117:            /** 
118:             * This testcase only calls the methods with condition=false..
119:             */
120:            public static class PartCoverage1 extends TestCase {
121:                /**
122:                 * Creates a new test.
123:                 * @param name Name of the test.
124:                 */
125:                public PartCoverage1(String name) {
126:                    super (name);
127:                }
128:
129:                /** Covers parts of the code. */
130:                public void testAll() {
131:                    CoverFor ci = new CoverFor();
132:
133:                    assertEquals(9, ci.simpleFor(4));
134:                }
135:
136:            }
137:
138:            /** 
139:             * This testcase only calls the nestedIf methods with parameters 
140:             * (true, true). The other methods are fully covered.
141:             */
142:            public static class PartCoverage2 extends TestCase {
143:                /**
144:                 * Creates a new test.
145:                 * @param name Name of the test.
146:                 */
147:                public PartCoverage2(String name) {
148:                    super (name);
149:                }
150:
151:                /** Covers parts of the code. */
152:                public void testAll() {
153:                    CoverFor ci = new CoverFor();
154:
155:                    assertEquals(5, ci.simpleFor(0));
156:                    assertEquals(9, ci.simpleFor(4));
157:
158:                    assertEquals(5, ci.expressionFor(0, 0));
159:                    assertEquals(9, ci.expressionFor(4, 8));
160:                }
161:
162:            }
163:
164:            /**
165:             * Test for full coverage.
166:             */
167:            public static class FullCoverage extends TestCase {
168:                /**
169:                 * Creates a new test.
170:                 * @param name Name of the test.
171:                 */
172:                public FullCoverage(String name) {
173:                    super (name);
174:                }
175:
176:                /** Covers all the code. */
177:                public void testAll() {
178:                    CoverFor ci = new CoverFor();
179:
180:                    assertEquals(5, ci.simpleFor(0));
181:                    assertEquals(9, ci.simpleFor(4));
182:
183:                    assertEquals(5, ci.expressionFor(0, 0));
184:                    assertEquals(9, ci.expressionFor(4, 8));
185:                    assertEquals(10, ci.expressionFor(8, 5));
186:                }
187:            }
188:
189:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.