Tag: junit

如何从命令行运行JUnittesting用例

我想从命令行运行JUnittesting用例。 我该怎么做?

如何在JUnit4中以特定的顺序运行testing方法?

我想执行testing方法,由@Test按照特定的顺序注释。 例如: public class MyTest { @Test public void test1(){} @Test public void test2(){} } 我想确保每次运行MyTest之前都在test2() test1()之前运行test1() ,但是我找不到像@Test(order=xx)这样的注释。 我认为这对于JUnit来说非常重要,如果JUnit的作者不想要订单function ,为什么呢?

你如何断言在JUnit 4testing中引发了某个exception?

我怎样才能使用JUnit4惯用testing一些代码抛出exception? 虽然我当然可以做这样的事情: @Test public void testFooThrowsIndexOutOfBoundsException() { boolean thrown = false; try { foo.doStuff(); } catch (IndexOutOfBoundsException e) { thrown = true; } assertTrue(thrown); } 我记得有一个注释或一个Assert.xyz或者一个远远不够灵活的东西 ,在这种情况下,JUnit的精神要远不止于此。

如何testing具有私有方法,字段或内部类的类?

如何使用JUnittesting具有内部私有方法,字段或嵌套类的类? 为了能够运行一个testing,改变一个方法的访问修饰符似乎是不好的。

System.out.println()的JUnit测试

我需要为一个设计不好的旧应用程序编写JUnit测试,并将大量错误消息写入标准输出。 当getResponse(String request)方法行为正确时,它返回一个XML响应: @BeforeClass public static void setUpClass() throws Exception { Properties queries = loadPropertiesFile("requests.properties"); Properties responses = loadPropertiesFile("responses.properties"); instance = new ResponseGenerator(queries, responses); } @Test public void testGetResponse() { String request = "<some>request</some>"; String expResult = "<some>response</some>"; String result = instance.getResponse(request); assertEquals(expResult, result); } 但是,当它变得格式不正确的XML或不理解请求时,它返回null并写入一些东西到标准输出。 有没有什么办法来断言在JUnit的控制台输出? 为了抓住这样的情况: System.out.println("match found: " + strExpr); System.out.println("xml not […]