2011-12-16 88 views
0

通过使用JUnit 4为我提供Android样本测试项目只有2-3个java文件。 我试图做到这一点。Junit 4亚军在Android测试项目“示例项目”

我的主测试文件。

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 { 
} 

和我制成另一个测试文件作为JUnit 4中是

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 { 
    } 
} 

但在执行错误显示的时间:

SampleTest:无法启动测试

请给我一些解决方案。

谢谢

回答

0

您没有任何@Test方法。

地址:

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

以下步骤为我工作:

  1. 创建新的JUnit(而不是 “Android的JUnit测试”)Testconfiguration:enter image description here
  2. 添加一个新的测试发射器: enter image description here
  3. 选择以下启动器:enter image description here

有了这个配置,我可以运行我的单元测试。他们在电脑上运行,而不是在电话上运行。希望这可以帮助。