Source Code Cross Referenced for Runner.java in  » Testing » MockCreator » net » sf » mockcreator » 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 » MockCreator » net.sf.mockcreator 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package net.sf.mockcreator;
002:
003:        import junit.framework.Test;
004:        import junit.framework.TestResult;
005:        import junit.framework.TestSuite;
006:
007:        import junit.textui.TestRunner;
008:
009:        import java.io.File;
010:
011:        import java.util.ArrayList;
012:        import java.util.Iterator;
013:        import java.util.List;
014:
015:        /**
016:         * Scans directories to find *Test.java files and
017:         * adds them into list of tests; if class name is passed as CLI argument,
018:         * performs that test only
019:         *
020:         * @author dozen
021:         */
022:        public class Runner extends TestSuite {
023:            static String[] args = null;
024:
025:            /**
026:             * Main entry point for CLI run.
027:             *
028:             * @param args Contains test names if any.
029:             */
030:            public static void main(String[] a) {
031:                args = a;
032:                ListenedRunner.run(suite());
033:                System.exit(ListenedRunner.tr.wasSuccessful() ? 0 : 1);
034:            }
035:
036:            /**
037:             * Forms testsuite to run
038:             *
039:             * @param List of test classes.
040:             *
041:             * @return The suite
042:             */
043:            public static Test suite() {
044:                Class[] params = new Class[] { String.class };
045:                Object[] constructparams = new Object[1];
046:
047:                TestSuite suite = new TestSuite();
048:
049:                List lst = new ArrayList();
050:
051:                if ((args != null) && (args.length > 0)) {
052:                    lst.add(args[0]);
053:                } else {
054:                    lst = scan(".", "", lst);
055:                }
056:
057:                // iterate all passed/found tests
058:                Iterator tit = lst.iterator();
059:
060:                while (tit.hasNext()) {
061:                    String test = (String) tit.next();
062:
063:                    // add the test; ignore missed
064:                    try {
065:                        Class testCase = Class.forName(test);
066:                        suite.addTestSuite(testCase);
067:                    } catch (ClassNotFoundException ex) {
068:                        System.err.println("Test class was not found: " + test);
069:                    }
070:                }
071:
072:                return suite;
073:            }
074:
075:            /**
076:             * Scans given directory for Test*.java files.
077:             *
078:             * @param dir Directory Name
079:             * @param name File name or subdir name
080:             * @return List of collected names
081:             */
082:            private static List scan(String dir, String name, List lst) {
083:                String base = dir + "/" + name;
084:
085:                File fil = new File((base == null) ? "." : base);
086:
087:                if (fil.isDirectory()) {
088:                    // scan directory for files
089:                    String[] names = fil.list();
090:
091:                    for (int i = 0; i < names.length; i++) {
092:                        scan(base, names[i], lst);
093:                    }
094:                } else {
095:                    if ((name.indexOf("Test") >= 0) && name.endsWith(".class")
096:                            && (name.indexOf("$") < 0)
097:                            && (name.indexOf("TestCase.class") < 0)) {
098:                        // found a test; store it in Java package notation
099:                        String toadd = base;
100:
101:                        while ((toadd.charAt(0) == '.')
102:                                || (toadd.charAt(0) == '/')) {
103:                            toadd = toadd.substring(1, toadd.length());
104:                        }
105:
106:                        toadd = toadd.replace('/', '.');
107:                        toadd = toadd.substring(0, toadd.lastIndexOf(".class"));
108:                        lst.add(toadd);
109:                    }
110:                }
111:
112:                return lst;
113:            }
114:
115:            /**
116:             * Prints usage instructions.
117:             */
118:            public static void Usage() {
119:                System.out.println("Usage:");
120:                System.out
121:                        .println("junit.textui.TestRunner de.abstract.Suite <Tests>");
122:            }
123:
124:            public static class ListenedRunner extends junit.textui.TestRunner {
125:                public static TestResult tr;
126:
127:                protected TestResult createTestResult() {
128:                    if (tr == null) {
129:                        tr = new TestResult();
130:                    }
131:
132:                    return tr;
133:                }
134:
135:                // dozen: I hate the way JUnit provides so-called extensibility >:E
136:                static public TestResult run(Test test) {
137:                    TestRunner runner = new ListenedRunner();
138:
139:                    return runner.doRun(test);
140:                }
141:            }
142:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.