maven junit testng 问题

maven构建的环境下,测试使用的是testNG。由于想看测试的覆盖率,于是装了个djunit插件(djunit基于junit)。
现象是:testNG运行ok,但是用junit或者djunit运行报错:
junit.framework.AssertionFailedError: No tests found in XXXX(package-name)
我的测试文件是这么写的:
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
import XXX.TsTypeMapping;
import XXX.common.test.base.AbstractTestBase;
public class TestTsTypeMapping extends AbstractTestBase {
@BeforeClass
public static void beforeClass() throws Exception {
...
}
@Test
public void testTsTypeMapping() {
...
}
}
其中,class名以TestXXX开始,没问题;测试方法testXXX也没问题;
class AbstractTestBase 是extends TestCase的应该也没问题;
@Test也标记了 以上4点都满足junit的标准的

ps:我另外一个project里面也是这么测试的,testclass去extends AbstractTestBase,testNg和junit,djunit都可以跑的很流畅。现在的project里的testclass和之前的project的testclass 都是extends同一个AbstractTestBase的
希望指点究竟是哪里出了问题,应该怎么修改才既可以testNg也可以junit测试。
(我怀疑是maven的pom设置,但是不知道怎么设置。)

[code="java"]
import junit.framework.TestCase;
import org.testng.annotations.Test;
import org.testng.annotations.BeforeMethod;

/**

  • author beneo
  • Date: Dec 10, 2010
  • Time: 10:42:36 AM
    */
    public class Demo extends TestCase {

    @BeforeMethod
    protected void setUp() throws Exception {
    System.out.println(" --- setup --- ");
    }

    @Test
    public void testDemon() {
    System.out.println(" --- ok --- ");
    }

}

[/code]

我成功了。。

[code="java"]


junit
junit
3.8.2


org.testng
testng
5.14.2


[/code]

[quote]
@BeforeClass
public static void beforeClass() throws Exception {
...
}
[/quote]
你得beofreclass没有override setup() in junit吧

[code="java"]
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
[/code]
你得@Test用的都是testng的annotations?

难道你希望junit3和testng混用??

用testng就好了,用的挺爽的

我今天也碰到这个问题了,junit和testng混合使用,仅testng有效啊!
http://confluence.highsource.org/display/~lexi/How+to+run+both+JUnit+and+TestNG+with+maven-surefire-plugin;jsessionid=5967281946AB5B464A304725DA7817F3