Source Code Cross Referenced for TestCase.java in  » Development » Javolution » javolution » testing » 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 » Development » Javolution » javolution.testing 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Javolution - Java(TM) Solution for Real-Time and Embedded Systems
003:         * Copyright (C) 2007 - Javolution (http://javolution.org/)
004:         * All rights reserved.
005:         * 
006:         * Permission to use, copy, modify, and distribute this software is
007:         * freely granted, provided that this notice is preserved.
008:         */
009:        package javolution.testing;
010:
011:        import j2me.lang.CharSequence;
012:
013:        /**
014:         * <p> This class represents a test case which can be used for validation, 
015:         *     performance and regression tests.</p>
016:         *     
017:         * <p> The structure of a test case is as follow:[code]
018:         *     class MyTestCase extends TestCase {
019:         *     
020:         *         // Prepares data/state in which to run the test.
021:         *         public void prepare() { ... } // Optional 
022:         *         
023:         *         // Executes the test (it may exercise the test case several times).
024:         *         public void execute() { ... } // Mandatory.
025:         *         
026:         *         // Returns the number of times the test case has been exercised (default 1).  
027:         *         public int count() { ... } // Optional
028:         *     
029:         *         // Validates the results. 
030:         *         public void validate() { ... } // Optional.
031:         *         
032:         *         // Cleanups after execution (e.g. release resources).  
033:         *         public void cleanup() { ... } // Optional
034:
035:         *     }[/code]
036:         *     It should be noted that some testing contexts (e.g. {@link TimeContext})
037:         *     may run the sequence (prepare, execute, validate, cleanup) multiple 
038:         *     times to calculate for example the average execution time (
039:         *     {@link #validate validation} in that case is performed only once
040:         *     after the last run). Here is an example of test case 
041:         *     implementation for the <code>HashMap.put(key, value)</code> method:[code]
042:         *     class HashMap_put extends TestCase {
043:         *         private HashMap _map;
044:         *         private int _size;
045:         *                   
046:         *         public HashMap_put(int n) { 
047:         *             _size = 0; 
048:         *             Index.setMinimumRange(0, n); // Preallocates.
049:         *         }               
050:         *         
051:         *         public void prepare() {
052:         *             _map = new HashMap();
053:         *         }
054:         *         
055:         *         public void execute() {
056:         *             for (int i=0; i < _size;) {
057:         *                 _map.put(Index.valueOf(i), Index.valueOf(i++));
058:         *             }
059:         *         }
060:         *         
061:         *         public int count() { // Number of put operations performed. 
062:         *             return _size;
063:         *         }
064:         *         
065:         *         public void validate() {
066:         *             TestContext.assertTrue("Wrong size", _size == _map.size());
067:         *             for (int i=0; i < _size;) {
068:         *                 if (!TestContext.assertEquals(_map.get(Index.valueOf(i)), Index.valueOf(i++)))
069:         *                      break; // Error, no need to continue.
070:         *             }
071:         *              
072:         *             // Asserts performance.
073:         *             long avgTime = TimeContext.getAverageTime("ns");
074:         *             TestContext.assertTrue(avgTime + "ns too slow!", avgTime < 100);
075:         *         }
076:         *         
077:         *         public CharSequence getDescription() {
078:         *            return "java.util.HashMap.put(key, value) - " + n + " entries added";
079:         *         }
080:         *    };[/code]
081:         *    Test cases are typically grouped into a {@link TestSuite}:[code]
082:         *    public HashMapTests extends TestSuite {
083:         *        public void run() {
084:         *            TestContext.info("Test put(key, value) for various size");
085:         *            TestContext.test(new HashMap_put(10));
086:         *            TestContext.test(new HashMap_put(100));
087:         *            TestContext.test(new HashMap_put(1000));
088:         *            ...
089:         *        }
090:         *    }
091:         *    TimeContext.enter(); // To measure execution time.
092:         *    try {
093:         *        new HashMapTests().run();
094:         *    } finally {
095:         *        TimeContext.exit();
096:         *    }[/code] </p>
097:         *
098:         * @author  <a href="mailto:jean-marie@dautelle.com">Jean-Marie Dautelle</a>
099:         * @version 5.2, August 5, 2007
100:         * @see     TestContext
101:         */
102:        public abstract class TestCase {
103:
104:            /**
105:             * Default constructor.
106:             */
107:            protected TestCase() {
108:            }
109:
110:            /**
111:             * Prepares the test case execution (the default implementation does 
112:             * nothing).
113:             */
114:            public void prepare() {
115:                // Does nothing.
116:            }
117:
118:            /**
119:             * Executes this test case (possibly multiple times in which case 
120:             * the {@link #count()} method should be overriden).
121:             */
122:            public abstract void execute();
123:
124:            /**
125:             * The number of times the test case is exercised (default <code>1</code>).
126:             * 
127:             * @return the number of test case occurences in {@link #execute}.
128:             */
129:            public int count() {
130:                return 1;
131:            }
132:
133:            /**
134:             * Validates the test results (the default implementation does 
135:             * nothing).
136:             */
137:            public void validate() {
138:                // Does nothing.
139:            }
140:
141:            /**
142:             * Cleanup once test is complete (the default implementation does 
143:             * nothing).
144:             */
145:            public void cleanup() {
146:                // Does nothing.
147:            }
148:
149:            /**
150:             * Returns the description of this test case or <code>null</code> if none.
151:             * 
152:             * @return the description or <code>null</code>
153:             */
154:            public CharSequence getDescription() {
155:                return null;
156:            }
157:
158:            /**
159:             * Returns the <code>String</code> representation of this test case 
160:             * (the description or the class name by default).
161:             * 
162:             * @return the string representation of this test case. 
163:             */
164:            public String toString() {
165:                CharSequence description = getDescription();
166:                return description == null ? this.getClass().getName()
167:                        : description.toString();
168:            }
169:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.