0

In my maven project, I have module A that is dependent on module B. In my module A test case, I am trying to extend one of module B's test case, however I encountered the following trouble whereby Caused by: java.lang.ClassNotFoundException: module-B.TestCase.

Is the reason because the tests themselves are not packaged into the jar? Any idea how to solve this?

goh
  • 27,631
  • 28
  • 89
  • 151
  • 2
    http://stackoverflow.com/questions/174560/sharing-test-code-in-maven#174670 has answer to similar problem – prunge Mar 28 '13 at 04:53
  • @prunge, thanks! i just happened to saw it too. will close this question. – goh Mar 28 '13 at 04:55

1 Answers1

2

Correct, by default maven does not package anything under src/test into the final artifact. The purpose of the unit test is as a compile-time checks ensuring the code behaves as they're intended to. Unit tests are not designed to be exported and used by other module.

If you find yourself wanting to import another module's unit test, maybe worth restructuring your code such that the reusable portion of the unit test is in their own module (eg: create a GenericUnitTest class in its own jar that gets imported by both Module A & Module B unit test)

gerrytan
  • 40,313
  • 9
  • 84
  • 99