How can I force maven to use my mock version of dependencies during the test phase.

Posted by Jayd16 on Stack Overflow See other posts from Stack Overflow or by Jayd16
Published on 2010-03-31T23:16:56Z Indexed on 2010/03/31 23:23 UTC
Read the original article Hit count: 249

Filed under:

Hi, so I have a Java application with a that accesses some web services. I want to mock out the appropriate classes so I can just use a few hard coded request/responses and I want maven to seamlessly use them during the tests and ignore them during the final build.

I want maven2 to:

1)compile my mock classes
2)compile the main classes that depend on the mocked code
3)run tests
4)recompile any main classes with the real dependencies, not my mocks
5)finish up the maven install

Ideally I want to just name my mock classes the same as my main class and just keep them in src/test/mocks or something. I'm kind of new to maven and so far it looks like maven will only compile the src/main and then src/test but I'm hoping I can have my way. Any ideas?

© Stack Overflow or respective owner

Related posts about maven-2