作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在做一个关于使用驱动程序类执行服务器测试用例的教程。 Eclipse 错误 Pane 显示错误消息:java.lang.Exception: No runnable methods。错误消息发生在
驱动程序类尝试运行异常测试类。
基于 pm 这个帖子:java.lang.exception no runnable methods junit .似乎应该在测试类中使用 @Test 注释或将 Junit Jar 文件更新到最新版本将解决该问题。
Junit Jar 文件版本:4.11
请检查我的代码并告诉我我应该做哪些修改以避免错误消息。谢谢!
驱动类:
import org.junit.runner.*;
import org.junit.runners.Suite;
@RunWith(Suite.class)
@Suite.SuiteClasses({
basicAnnotation.class,
personTest.class,
exceptionTesting.class
})
public class UnitTestDriver {
}
import org.junit.*;
import org.junit.Test;
public class exceptionTesting
{
public class junitTest2{
@Test (expected = ArithmeticException.class)
public void divisionWithException(){
int i = 1/0;
}
}
}
最佳答案
问题是junitTest2 嵌套在exceptionTesting 中。你有两个选择来解决它:
1)摆脱在顶级类中进行测试的内部类:
import org.junit.*;
import org.junit.Test;
public class exceptionTesting
{
@Test (expected = ArithmeticException.class)
public void divisionWithException(){
int i = 1/0;
}
}
import org.junit.*;
import org.junit.Test;
@RunWith(Enclosed.class)
public class exceptionTesting
{
public static class junitTest2{
@Test (expected = ArithmeticException.class)
public void divisionWithException(){
int i = 1/0;
}
}
}
关于junit4 - Junit - java.lang.Exception : No runnable methods,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16814365/
我是一名优秀的程序员,十分优秀!