【发布时间】:2013-09-19 12:44:15
【问题描述】:
我需要以下测试
@runwith(cache, memory)
class CollectionA is -- this is a suite (aka folder)
class Cache { -- this is a sub-suite (aka folder)
@test testCache1() -- this is a method (aka file)
@test testCache2()
@test testCache3()
}
class RAM { -- this is a sub-suite (aka folder)
@test testRAM1()
@test testRAM2()
}
@test testIO()
@test testKeyboard()
@test testMouse()
@test testMonitor()
@test testPower()
@test testBoot()
请注意,只有 Cache 和 RAM 需要分组。层次结构有助于对抗复杂性并运行相关测试,例如必要时单独缓存子系统。问题是我使用@runwith 进行分组时,JUnit 会忽略除 RAM 和 Cache 集合之外的所有单个测试方法。在 JUnit 设计中似乎不能有兄弟文件和文件夹。 the official example of grouping 中的 cmets 也暗示了
@RunWith(Suite.class)
@Suite.SuiteClasses({
TestA.class,
TestA.class
})
public class FeatureTestSuite {
// the class remains empty,
// used only as a holder for the above annotations
// HEY!!! WHAT ABOUT MY @Tests HERE?
}
答案表明我是否需要包装每一个测试,例如testPower 进入他们的单调套装或扁平套装 - 如果完全摆脱层次结构。
那么,JUnit 被设计成不允许将单个文件(@test 方法)与文件夹(@runwith 套件)混合是正确的吗?为什么?如何解决这个问题? @runwith.Suite 可能有替代品吗?
【问题讨论】:
-
我不明白你在说什么 WRT 文件和文件夹。您不能在套件中进行测试。因此,但是测试类中的测试并包含套件中的测试。只要测试是公开的,就可以将测试包含在套件中,对测试所在的文件夹没有任何限制。您可以添加与套件位于同一文件夹(包)中的测试以及位于不同文件夹(包)中的测试。
-
我看到你说我不能在套件中进行测试。你能不能给出一个答案,并解释一下设计,这样我就不会在这个陷阱上浪费时间。
-
问题是所有的类都应该是它们自己的文件。不要使用子/内部类。
-
我不明白。如果您说不可能在套件中进行测试,而套件类可以在任何地方找到,那么为什么嵌套会产生任何问题? IMO,在语法上嵌套逻辑嵌套的东西是件好事。
-
要使用内部类,您将使用
Enclosed运行器,而不是Suite运行器。使用Suite的单独类允许您 1:拥有更小的文件 2:运行单独的测试
标签: junit grouping hierarchy folding