Details
-
Type:
Improvement
-
Status:
Closed
-
Priority:
Major
-
Resolution: Fixed
-
Affects Version/s: 1.1.0
-
Fix Version/s: 2.0.0
-
Component/s: JMock 2.x.x Library
-
Labels:None
-
Testcase included:yes
Description
I wrote a code to support JUnit 4 without making the test class inherit from MockObjectTestCase.
I attached the code with tests.
Please verify if this approach is feasible.
There are three main features:
1. Separated the mock creation from the MockObjectTestCase hierarchy.
This is achieved by creating new classes (org.jmock.junit4.MockManager and org.jmock.cglib.junit4.MockManager in my source code).
Usage:
MockManager mockManager;
Mock mock;
@Before public void setUp( ) {
mockManager = new MockManager( );
mock = mockManager.mock( .. );
}
2. Separated the verification from the VerifyingTestCase hierarchy.
A new class (org.jmock.junit4.VerificationManager in my source code) is created. The MockManager class above has a delegated verify method to delegate verification to VerificationManager.
Usage:
@After public void tearDown( ) {
mockManager.verify( );
}
3. The mock supports methods (e.g. eq(..) ) are statically imported (just like assert.. methods).
Separated the mock support methods e.g. eq(..) from TestCase hierachy.
A new class (org.jmock.junit4.MockSupporter in my source code) with static methods is created.
Usage (same as before other than the static import):
import static org.jmock.junit4.MockSupporter.*;
...
mock.expects( once( ) ).method( "methodName" ).with( eq( .. ) ).will( returnValue( .. ) );
Two test classes (one for mocking interface and the other for class with CGLIB) to test those features describe how to use them. By the way, I used JUnit 4 format for those test classes.
Also just as an idea, I modified the existing MockObjectTestCase, MockObjectSupportTestCase, and VerifyingTestCase to delegate their functionalities to the corresponding Managers above, so that they can be still used as they have been used without the code duplication. In my source code, I put them under org.jmock.oldJUnit and org.jmock.cglib.oldJUnit because I didn't want to change the existing code because this is just an idea.
The attached code follows the default Maven structure, i.e. the source codes are under src/main/java and the test codes are under src/test/java because I am not able to access CVS so I don't know what test directory structure jMock has...
If this approach is feasible, please give me an anonymous cvs read access so that I can run the existing tests there with this code.
Thank you.
P.S.
The code is based on 1.1.0-RC1 and JUnit 4.1.