Search code examples
javajunitjunit4

How do I move JUnit classes into a package?


I'm working on a Java project, and currently have JUnit 4 set up to run some unit tests.

In this makefile: https://github.com/bprollinson/larp/blob/master/Makefile I'm using the "test" target to run tests. This works fine.

However, I want to change the directory structure of the unit tests from being flat (all in src/test) to mirror the application code directory structure. Application directory structure currently looks like:

src/main/larp/parser/contextfreelanguage src/main/larp/parser/regularlanguage src/main/larp/parsertree/regularlanguage ...

I've tried moving a test class into this directory structure, then adding the appropriate namespace declaration at the top of the file (e.g. moved src/tests/DFATest.java into src/test/larp/automaton and added "package larp.automaton;" at the top).

However, it generates the following error: Could not find class [Classname]

Is there something special I need to do to get JUnit to tie into namespaces in unit test classes.


Solution

  • check your project location and find your .class file and then edit and mention new directory structure instead of src/test.