Can't Run Junit 4 Test Case in Eclipse Android Project

Can't run JUnit 4 test case in Eclipse Android project

Having searched Google for an answer, this looks like it might have something to do with Android development tools.

Below are steps taken from this comment thread:

  1. Right click on the project -> run -> run configuration
  2. Select your Junit project
  3. Go to the classpath tab
  4. remove the Android framework entry
  5. select bootstrap entries
  6. click on advanced
  7. select Add Library
  8. Ok
  9. Chose "JRE System Library"
  10. Next
  11. finish
  12. You need to also add the JUnit library so follow the steps 5 to 11 and select the "Junit" instead of "JRE System Library"
  13. You can now run your project as Junit.

No JUnit tests found' in Eclipse

Right Click on Project > Properties > Java Build Path > Add the Test folder as source folder.

All source folders including Test Classes need to be in Eclipse Java Build Path. So that the sources such as main and test classes can be compiled into the build directory (Eclipse default folder is bin).

can't find run as junit test in eclipse

Make sure your eclipse environment is using JUnit 4. JUnit 3 doesn't make use of annotations (it uses the old extends TestCase style)

There are few things to double check:

Window > Preferences > Java > JUnit

Are you seeing junit4 or junit3 imports? If that looks good, make sure the project itself is using JUnit4 instead of JUnit3.

Right Click on project > Properties > Java Build Path > Libraries

Is JUnit4 included there? Is anything JUnit related there? If JUnit3 is in there, click on it and click Remove. Then click Add Library... and follow the prompts from there to add JUnit again.

Out of curiosity, are the JUnits run outside of eclipse? Like with a mvn install or whatever build target you have for Ant that'll run JUnits

JUnit test won't run when I Run-As from the test.java file

This sort of problem is always difficult to debug without your full environment, but it sounds like you have a Run Configuration which is corrupted or doesn't match your classes or something like that. Try deleting the Run Configuration and retrying.

When you select Run As JUnit, Eclipse creates a Run Configuration specific to your JUnit class.

To fix this, in Eclipse, open Run->Run Configuration. In the list at the left, find the run configuration that applies to QuaternionTest, make sure it's the Run Configuration in the JUnit section. Delete it (right click, select delete). Then try again.

Sample Image



Related Topics



Leave a reply



Submit