私は今テストを書いていますが、最初はすべて非常に似ていることに気づいています。
@Test
public void testThisMemoryOperation() {
Assert.assertEquals("Sanity check failed, shouldn't be anything in memory yet.",
0, memoryManager.getObjectsInMemory());
/* ... */
}
@Test
public void testThatMemoryOperation() {
Assert.assertEquals("Sanity check failed, shouldn't be anything in memory yet.",
0, memoryManager.getObjectsInMemory());
/* ... */
}
@Test
public void testTheOtherMemoryOperation() {
Assert.assertEquals("Sanity check failed, shouldn't be anything in memory yet.",
0, memoryManager.getObjectsInMemory());
/* ... */
}
これは不必要に繰り返されるようです。このコードを各テストの開始時に単純なメソッド呼び出しに置き換えて健全性チェックアサーションを実行する@Rule
こともできますが、特定のメソッドを実行する前にこのテストを単純に実行するために使用できるネイティブJUnitアノテーションはありますか?