Java Doc for PathableTestSuite.java in  » Library » apache-common-Logging » org » apache » commons » logging » 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 » Library » apache common Logging » org.apache.commons.logging 
Source Cross Reference  Class Diagram Java Document (Java Doc) 


org.apache.commons.logging.PathableTestSuite

PathableTestSuite
public class PathableTestSuite extends TestSuite (Code)
Custom TestSuite class that can be used to control the context classloader in operation when a test runs.

For tests that need to control exactly what the classloader hierarchy is like when the test is run, something like the following is recommended:

 class SomeTestCase extends TestCase {
 public static Test suite() throws Exception {
 PathableClassLoader parent = new PathableClassLoader(null);
 parent.useSystemLoader("junit.");
 PathableClassLoader child = new PathableClassLoader(parent);
 child.addLogicalLib("testclasses");
 child.addLogicalLib("log4j12");
 child.addLogicalLib("commons-logging");
 Class testClass = child.loadClass(SomeTestCase.class.getName());
 ClassLoader contextClassLoader = child;
 PathableTestSuite suite = new PathableTestSuite(testClass, child);
 return suite;
 }
 // test methods go here
 }
 
Note that if the suite method throws an exception then this will be handled reasonable gracefully by junit; it will report that the suite method for a test case failed with exception yyy.

The use of PathableClassLoader is not required to use this class, but it is expected that using the two classes together is common practice.

This class will run each test methods within the specified TestCase using the specified context classloader and system classloader. If different tests within the same class require different context classloaders, then the context classloader passed to the constructor should be the "lowest" one available, and tests that need the context set to some parent of this "lowest" classloader can call

 // NB: pseudo-code only
 setContextClassLoader(getContextClassLoader().getParent());
 
This class ensures that any context classloader changes applied by a test is undone after the test is run, so tests don't need to worry about restoring the context classloader on exit. This class also ensures that the system properties are restored to their original settings after each test, so tests that manipulate those don't need to worry about resetting them.

This class does not provide facilities for manipulating system properties; tests that need specific system properties can simply set them in the fixture or at the start of a test method.

Important! When the test case is run, "this.getClass()" refers of course to the Class object passed to the constructor of this class - which is different from the class whose suite() method was executed to determine the classpath. This means that the suite method cannot communicate with the test cases simply by setting static variables (for example to make the custom classloaders available to the test methods or setUp/tearDown fixtures). If this is really necessary then it is possible to use reflection to invoke static methods on the class object passed to the constructor of this class.

Limitations

This class cannot control the system classloader (ie what method ClassLoader.getSystemClassLoader returns) because Java provides no mechanism for setting the system classloader. In this case, the only option is to invoke the unit test in a separate JVM with the appropriate settings.

The effect of using this approach in a system that uses junit's "reloading classloader" behaviour is unknown. This junit feature is intended for junit GUI apps where a test may be run multiple times within the same JVM - and in particular, when the .class file may be modified between runs of the test. How junit achieves this is actually rather weird (the whole junit code is rather weird in fact) and it is not clear whether this approach will work as expected in such situations.




Constructor Summary
public  PathableTestSuite(Class testClass, ClassLoader contextClassLoader)
     Constructor.

Method Summary
public  voidrunTest(Test test, TestResult result)
     This method is invoked once for each Test in the current TestSuite.


Constructor Detail
PathableTestSuite
public PathableTestSuite(Class testClass, ClassLoader contextClassLoader)(Code)
Constructor.
Parameters:
  testClass - is the TestCase that is to be run, as loaded bythe appropriate ClassLoader.
Parameters:
  contextClassLoader - is the loader that should be returned bycalls to Thread.currentThread.getContextClassLoader from test methods(or any method called by test methods).




Method Detail
runTest
public void runTest(Test test, TestResult result)(Code)
This method is invoked once for each Test in the current TestSuite. Note that a Test may itself be a TestSuite object (ie a collection of tests).

The context classloader and system properties are saved before each test, and restored after the test completes to better isolate tests.




www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.