Junit 4 runner in android test project “Sample Project”

限于喜欢 提交于 2019-12-25 03:59:14

问题


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


回答1:


The following steps worked for me:

  1. Create new JUnit (and NOT "Android Junit Test") Testconfiguration:

  2. Add a new test launcher:

  3. Choose the following launcher:

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




回答2:


You don't have any @Test methods.

Add:

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


来源:https://stackoverflow.com/questions/8530666/junit-4-runner-in-android-test-project-sample-project

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!