Jules
Jules

Reputation: 7213

Why is my JUnit test not running in Eclipse?

It's been 3 hours now and I still didn't find a solution, even though I seem to have read all related questions already.

I am building an Android application and I just want to create a couple of simple Unit Tests that test my basic functions. I don't need to test any Android related logic or activity features.

So I have created a new directory in my solution in which I have created a new JUnit Test Case.

To keep things simple my test methods are not testing much yet, but even when doing a Right Click > Run As > JUnit Test, it's not doing anything.

As you can see in my screenshot the JUnit pane on the left shows my test is terminated but does not show any test that has been executed.

I have created a simple Unit Test in a new Java Project and then it's working. If I repeat the same steps in a new Android Application Project it's not working.

What do I need to do to run my simple Unit Tests?!

Thanks!

Screenshot of my non-running Unit Test

(My Compiler Compliance Level is 1.6)

Upvotes: 2

Views: 14838

Answers (5)

Manisha
Manisha

Reputation: 111

The java Build path of the project has Junit4.jar lets say and the Run configuration for the test you are running has Junit5 - then it causes to terminate and nothing happens.

Upvotes: 0

Mykhaylo Adamovych
Mykhaylo Adamovych

Reputation: 20956

Go to Window -> Show View -> Error Log to see what the actual error is.
For my case it was No test found with test runner 'Junit 5'.
Then one can google for respective solution.

Upvotes: 3

Prashant
Prashant

Reputation: 1

This is related to Memory Issue. Simply add these line in VM argument: right click on Junit Test -> Run as -> Run Configuration -> Arguments -> add "-XX:MaxPermSize=512m" under VM argument

Upvotes: 0

Big Al
Big Al

Reputation: 1030

You can use AndroidTestCase, which inherits from junit.framework.TestCase, not org.junit.Test.

Upvotes: 0

Adam Arold
Adam Arold

Reputation: 30528

You either don't have JUnit on the build path or you don't have the library (jar) at hand. Make sure both are in place.

I think you will need an unit test suite if all else fails:

@RunWith(Suite.class)
@SuiteClasses({ GpsLocationTest.class })
public class AllTests {

} 

There is one more thing you can do: check whether you import the right @Test annotation. Restart Eclipse and clean your project if the problem persists.

You may want to refer to the vogella guide about unit testing.

Upvotes: 0

Related Questions