Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/334.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 在junit4中未找到任何测试_Java_Junit_Junit4 - Fatal编程技术网

Java 在junit4中未找到任何测试

Java 在junit4中未找到任何测试,java,junit,junit4,Java,Junit,Junit4,我正在尝试使用Junit4 I,使用下面的类别 public class Example extends TestCase { public Example(String name) { super(name); } @Test public void exampletest() { //TO DO } } @RunWith(Suite.class) @SuiteClasses({ Example.class }) pu

我正在尝试使用Junit4 I,使用下面的类别

public class Example extends TestCase {

    public Example(String name) {
        super(name);
    }
    @Test
    public void exampletest() {
        //TO DO
    }
}

@RunWith(Suite.class)
@SuiteClasses({ Example.class })
public class Tests {
    TestSuite tests = new TestSuite();
        tests.addTest(new Example("exampletest"));  
}
它没有给我在junit4异常中找到的测试。有人可以告诉我为什么会出现这个异常
或者给出一个如何做的例子?

在JUnit4中,您不需要让您的测试用例扩展TestCase。但如果您这样做,那么您的@Test注释将被忽略,并且您必须按Test在测试方法名称之前加上前缀。 请尝试以下代码:

Example.java:

import org.junit.Test;
public class Example {
    @Test
    public void exampletest() {
        //TO DO
    }
}
Tests.java:

@RunWith(Suite.class)
@SuiteClasses({ Example.class })
public class Tests {
}

我的意思是,我需要对测试用例进行排序,以便使用TestSuite tests=newtestsuite();tests.addTest(新示例(“exampletest”));你能给出一些建议吗?根据设计,JUnit不允许推测测试的执行顺序。测试用例应该是独立的。当你写新的测试时,这是很公平的。另一种情况是,您必须使用遗留测试。看看这个:你可能需要写你自己的跑步者来实现你想要的。您可以派生套件运行程序,并使用Request.sortWith命令测试用例的执行。分开处理。