JSF & Java Blog

Discussion on Java and JSF, including Spring, Maven, Eclipse and Jenkins

Posts Categorized / Testing

Suppress logging in java unit tests

Here are a couple of different ways of suppressing logging when running unit tests. If you are using apache commons logging then you can suppress logging with the following code: If running your unit tests with JUnit, it is probably best to put this code in the setUp() method. However, if you only wanted it […]

0

Mocking Statics and IllegalStateException: no last call on a mock available

If you use PowerMock to mock a static object e.g. and encounter the following error: Check that you have prepared the Class for test using the @PrepareForTest annotation. e.g. An excellent article discussing mocking statics by one of the PowerMock developers can be found here: http://blog.jayway.com/2009/05/17/mocking-static-methods-in-java-system-classes/ Note that you also need to @PrepareForTest any classes […]

1

Cobertura code coverage with Maven and PowerMock

If you use Powermock for unit testing with Maven and Cobertura for code coverage, you are likely to be affected by the following issue noted on the PowerMock issue tracker. If you did not have the maven-surefire-plugin forkmode configured to ‘pertest’, you would find that any tests annotated with @RunWith(PowerMockRunner.class) had zero percentage code coverage […]

3

Chaining EasyMock’s expectation return values

Recently I discovered quite a handy feature of EasyMock’s IExpectationSetters andReturn method. You are able to chain the return values so that you can return different values each time that expectation is called. Chaining Easymock’s expectation return values becomes useful if you consider the following method, where Voucher is an object that cannot be instantiated […]

0