开发者

Why would extending JerseyTest vs extending TestCase cause no tests to be found

I am attempting to get the Jersey test framework working. We are building using maven 1.x. I've created the following testcase...

public class SomeResourceTest extends JerseyTest
{
    public SomeResourceTest () throws Exception 
    {
        super(new WebAppDescriptor.Builder(PACKAGE_NAME)
                      .contextPath(PATH).build());
    }    
    @Test
    public void t开发者_运维知识库estSomething() 
    {
        Assert.assertEquals(true, true);
    }
}

When I build, I get no tests found in SomeResourceTest.

Now, when I change the testcase to extend junit.framework.TestCase, the test runs just fine.

Any clue what might be causing the problem? JerseyTest is supposed to extend TestCase, so I am assuming it to be some other configuration problem.


Any clue what might be causing the problem? JerseyTest is supposed to extend TestCase (...)

The Jersey Test Framework is build over JUnit 4.x so, no, it doesn't.

To run JUnit 4.x tests with Maven 1.x, you'll have to:

  • Add Junit 4.X in your dependencies

  • Use the JUnit4TestAdapter in your test classes:

    /**
     * @return instance of this as Junit test case
     */
    public static junit.framework.Test suite()
    {
        return new JUnit4TestAdapter(MyTestClass.class);
    }
    
  • Use a JDK 5+

See http://jira.codehaus.org/browse/MPTEST-65.


What version of JerseyTest are you using? The latest version relies on JUnit 4 and does not extend TestCase.

Also, your test is a bit confusing. It has @Test which implies you are using JUnit 4 and shouldn't extend TestCase. But it sounds like you are still relying on the testXXX and TestCase subclass convention from JUnit 3.8 in your description.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜