JMockit is one of the many mocking frameworks available for unit testing in Java. If you have to unit test you'll invariably end up mocking objects for third party classes and for stubbing.
I assume you already know JUnit. We'll see step by step in very short tutorials that'll help you start using jmockit. I'll be trying to keep each one as crisp as possible. If you want more details.You can ask them in comments section below...
I am yet to understand some of the JMockit features completely, so please bear with me if I have not covered it in entirety.
- What is Mocking in unit Testing?
- How does JMockit support mocking?
- How to add JMockit to an eclipse project?
- How to run a test case with JMockit?
- How to mock default constructors(or constructors with no parameters) in JMockit?
- How to mock constructors with parameters (or those that take arguments) ?
- How to mock static initialization blocks in JMockit?
- How to mock public methods in JMockit
- How to mock private methods in JMockit?
- How to mock static methods in JMockit?
- How to invoke or test private methods in JMockit?
- How to throw exceptions in an Expectations block?
- Some more JMockit utilities before signing off.
Consider the code below:
Remember the to put the @Mock annotation above. I have spent hours trying to debug only to find out that I forgot.