Showing posts with label unit testing. Show all posts
Showing posts with label unit testing. Show all posts

Thursday, January 19, 2012

Maven Test Dependency

With the maven-jar-plugin's goal test-jar, it is possible to create testing dependencies.

When doing this it is important to include the dependency twice, once normally (main code) and again with <type>test-jar<type>. So long as the dependency is built first, maven will find the test code.

Note: Eclipse doesn't seem to care which if both dependencies are there, causing some confusion, but when you go to run mvn from the cli, it will care.

http://maven.apache.org/guides/mini/guide-attached-tests.html

Thursday, October 20, 2011

EasyMock: Capture passed in values

I was writing a unit test this morning where the void method I was testing created an instance of a objected and passed it into a subsequent method. I needed to capture that object so that I could verify that it was set up properly. EasyMock provides a way to do this.

http://blog.jayway.com/2009/03/25/easymock-capturing-arguments-from-multiple-calls/

example:

Capture captured = new Captured();
expect(serviceInstance.method(EasyMock.capture(captured)).andReturn(/* whatever */);

MyObject obj = captured.getValue();

//run unit tests on obj