user1101243
user1101243

Reputation: 1

Junit 4 runner in android test project "Sample Project"

Provide me Android sample test project with only 2-3 java files,by using JUnit 4. I was trying to do this.

My main test file.

import org.junit.runner.RunWith;
import org.junit.runners.Suite;
@RunWith(Suite.class)
@Suite.SuiteClasses({
SimpleMathTest.class
// add other classes here (comma separated)
})
public class TestSuite {
}

and I made another test file as JUnit 4 that is

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
public class SimpleMathTest {
    @BeforeClass
    public static void setUpBeforeClass() throws Exception {
    }
    @AfterClass
    public static void tearDownAfterClass() throws Exception {
    }
    @Before
    public void setUp() throws Exception {
    }
    @After
    public void tearDown() throws Exception {
    }
}

but at the time of execution Error displays:

SampleTest: Failed to launch test

please give me some solution.

Thanks

Upvotes: 0

Views: 909

Answers (2)

Mirco Widmer
Mirco Widmer

Reputation: 2149

The following steps worked for me:

  1. Create new JUnit (and NOT "Android Junit Test") Testconfiguration: enter image description here
  2. Add a new test launcher: enter image description here
  3. Choose the following launcher: enter image description here

With this configuration I can run my unit tests. They run on the pc and not on the phone. Hope this helps.

Upvotes: 2

oers
oers

Reputation: 18704

You don't have any @Test methods.

Add:

@Test
public void test()  {
    //Test code here
}

Upvotes: 0

Related Questions