JUnit和junit.framework.TestSuite-没有可运行的方法 [英] JUnit and junit.framework.TestSuite - No runnable methods

查看:355
本文介绍了JUnit和junit.framework.TestSuite-没有可运行的方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经进行了一些单元测试(在测试课中).我读过的教程说我应该为单元测试制作一个TestSuite.

I've made some unit tests (in test class). The tutorial I've read said that I should make a TestSuite for the unittests.

奇怪的是,当我直接运行单元测试(选择测试类-以jUnit测试运行)时,一切都工作正常,而当我在测试套件中尝试相同的操作时,总会有一个例外:java .lang.Exception:没有可运行的方法.

Odd is that when I'm running the unit test directly (selecting the test class - Run as jUnit test) everything is working fine, altough when I'm trying the same thing with the test suite there's always an exception: java.lang.Exception: No runnable methods.

这是测试套件的代码:

import junit.framework.Test;
import junit.framework.TestSuite;

public class AllTests {

public static Test suite() {
    TestSuite suite = new TestSuite("Test suite for com.xxx.yyyy.test");
    //$JUnit-BEGIN$
    suite.addTestSuite(TestCase.class);
    //$JUnit-END$
    return suite;
    }

}

有什么想法为什么不起作用?

Any ideas why this isn't working ?

推荐答案

我对蚂蚁没有任何经验-所以我现在不使用它来测试它.

I'm not experienced in ant - so I'm not using it for testing it right now.

搜索Internet似乎在混淆旧的jUnit 3.8和jUnit 4.0行为. 现在尝试一种使用新行为"的方法

Searching the internet it seems like I'm mixing up the old jUnit 3.8 and jUnit 4.0 behavior. Trying now a way to use the "new behavior"


现在可以使用了:

edited:
now it works:

AllTest更改为:

AllTest changed to:

import org.junit.runner.RunWith;
import org.junit.runners.Suite;
import org.junit.runners.Suite.SuiteClasses;


@RunWith(value=Suite.class)
@SuiteClasses(value={TestCase.class})
public class AllTests {

}

TestCase更改为:

TestCase changed to:

import static org.junit.Assert.assertTrue;
import org.junit.Test;

public class TestCase  {
@Test
    public void test1 {
        assertTrue (tmp.getTermin().equals(soll));
    }
}

这篇关于JUnit和junit.framework.TestSuite-没有可运行的方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆