使用JUnit测试内部类中的案例 [英] Test cases in inner classes with JUnit
本文介绍了使用JUnit测试内部类中的案例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我读到结构化单元测试每个类的测试类和每个方法的内部类。想象一下,这似乎是一种组织测试的方便方法,所以我在Java项目中尝试过。然而,内部类中的测试似乎根本没有被接受。
I read about Structuring Unit Tests with having a test class per class and an inner class per method. Figured that seemed like a handy way to organize the tests, so I tried it in our Java project. However, the tests in the inner classes doesn't seem to be picked up at all.
我这样做大致是这样的:
I did it roughly like this:
public class DogTests
{
public class BarkTests
{
@Test
public void quietBark_IsAtLeastAudible() { }
@Test
public void loudBark_ScaresAveragePerson() { }
}
public class EatTests
{
@Test
public void normalFood_IsEaten() { }
@Test
public void badFood_ThrowsFit() { }
}
}
JUnit不支持这个,还是我做错了?
Does JUnit not support this, or am I just doing it wrong?
推荐答案
public class ServicesTest extends TestBase {
public static class TestLogon{
@Test
public void testLogonRequest() throws Exception {
//My Test Code
}
}
}
让内部类静态适用于我。
Making the inner class static works for me.
这篇关于使用JUnit测试内部类中的案例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文