2

次のテストが必要です

@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()

キャッシュと RAM のみをグループ化する必要があることに注意してください。階層は複雑さに対処し、必要に応じてキャッシュ サブシステムなどの関連テストを単独で実行するのに役立ちます。@runwith を使用してそのグループ化を行うとすぐに発生する問題は、RAM およびキャッシュ コレクション以外のすべての単一テスト メソッドが JUnit によって無視されることです。JUnit の設計では、ファイルとフォルダーを兄弟にすることはできないようです。グループ化の公式例のコメントも、次のことを示唆しています。

@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 suites) の混合を禁止するように設計されているのは正しいでしょうか? なんで?これはどのように回避できますか? に代わるものがあるかもしれませ@runwith.Suiteんか?

4

2 に答える 2