7

When writing tests, I'd like to run them individually. Howver, since I have switched from the default Eclipse Java builder to Maven, this is not possible any more. Observations:

  1. Until today I could open a JUnit test source file and select Run as | JUnit test from the toolbar. Before I migrated to Maven, Eclipse built the unit test when needed.

  2. Since Maven, I get a ClassNotFoundException in case I have not explicitly compiled the tests before. I can bypass this if I select the POM and do Run as | Maven test. This will compile the tests and run all tests.

  3. If I select the unit test again and choose Run as | JUnit test from the toolbar now, it'll execute the test.

Since this is way too unconvenient, I'd like the "old" behavior back and I think this should only be a configuration problem.

I have

I'm giving up now.

How can I do efficient red-green refactoring, i.e. run only one unit test at a time without adding a run configuration for each single test?

Community
  • 1
  • 1
Thomas Weller
  • 55,411
  • 20
  • 125
  • 222
  • In general this is possible. I think you have a configuration problem with your Maven/Eclipse integration. Do both (Maven and Eclipse) use the same target directory (i.e. where the .class files are stored)? – Jan Sep 11 '15 at 14:26
  • @Jan: In Java Build File, I have "Default output folder" set to /target/classes. The source folders point there (/src/main/java, /src/main/resources) except the unit tests (src/test/java) which point to /target/test-classes. – Thomas Weller Sep 11 '15 at 14:35
  • In my POM I have removed and specific directory names, so it builds to /target/classes and /target/test-classes as well. – Thomas Weller Sep 11 '15 at 14:36
  • How did you "_switch from the default Eclipse Java builder to Maven_" in detail? Did you try to • create a clean new Maven project • copy the main/test sources/resources into it • adapt the `pom.xml` accordingly? – Gerold Broser Sep 12 '15 at 01:56

2 Answers2

0

Today I found out that the Java Builder was disabled:

Java Builder not configured

Enabling it returned the expected behavior.

Thomas Weller
  • 55,411
  • 20
  • 125
  • 222
0

This worked for me-

  1. Select the test file you want to run.
  2. Right click and open run configuration.
  3. Now go to classpath and move maven dependencies to the top and apply.
gauti
  • 11
  • 4