相关疑难解决方法(0)

在JUnit中的Test类中定义内部类时出错

我在从TestCase继承的Test类中为JUnit 3定义内部类时遇到一些问题.场景如下:

Foo.java

public class Foo {
  public void method() { ... }
}
Run Code Online (Sandbox Code Playgroud)

FooTest.java

public class FooTest extends TestCase {
  public class Bar extends Foo {
    public void method() { ... }
  }
  public void testMethod() { ... }
}
Run Code Online (Sandbox Code Playgroud)

现在,如果我从Eclipse运行它,测试运行正常,但如果我尝试从Ant任务运行它失败:

[junit] junit.framework.AssertionFailedError:类Foo $ Bar没有公共构造函数TestCase(String name)或TestCase()

Bar不是Test类,它只是Foo的一个子类,它覆盖了一些方法,在测试时我不需要做真正的事情.

我现在很迷茫,我不知道如何解决这个问题.是独立创建子类的唯一方法吗?

java reflection junit inner-classes junit3

10
推荐指数
2
解决办法
5402
查看次数

如何一次运行我所有的内部类junit测试

我按照描述的方法使用每个方法使用一个内部类来组织我的junit测试:

在这里,在一个haacked文章(关于nunit测试),和
这里,在这个SO问题

public class TestMyThing {

    public static class TestMyThingMethodOne {

        @Test
        public void testMethodOneDoesACertainBehaviour() {
            // terse, clear testing code goes here
        }

        @Test
        public void testMethodOneHasSomeOtherDesiredBehaviour() {
            // more inspiring testing code here
        }
    }

    public static class TestMyThingMethodTwo {
        ... etc
    }
}
Run Code Online (Sandbox Code Playgroud)

但是,当我尝试为此运行junit测试时,Eclipse会询问我要运行哪个内部类测试,而我只能选择一个.有没有一种方法可以指定我希望每个内部类中的每个测试都能运行TestMyThing类?

java eclipse junit

4
推荐指数
1
解决办法
2280
查看次数

标签 统计

java ×2

junit ×2

eclipse ×1

inner-classes ×1

junit3 ×1

reflection ×1