0
TestNGでhereのEasyMockの例を実行しようとしていて、奇妙な問題に直面しています。最初の2つのテストは正常に実行されますが、3つ目のテスト(getPriceDataAccessThrowsRuntimeException)は単独で実行すると正常に実行されます。しかし、私は2つの他の試験、個別に、またはすべて一緒に3番目のテストでそれを実行すると失敗し、私は以下の取得:EasyTickを使用してExceptionを予期するaddThrowの問題
FAILED: getPriceDataAccessThrowsRuntimeException
org.testng.TestException:
Expected exception java.lang.RuntimeException but got org.testng.TestException:
Expected exception java.lang.RuntimeException but got java.lang.AssertionError:
Unexpected method call DataAccess.getPriceBySku("3283947"):
次のテストコードです:
@Test
public void getPrice() throws Exception {
// Set expectations on mocks.
expect(mockedDependency.getPriceBySku(SKU)).andReturn(new BigDecimal(100));
// Set mocks into testing mode.
replay(mockedDependency);
final BigDecimal price = systemUnderTest.getPrice(SKU);
assertNotNull(price);
// Verify behavior.
verify(mockedDependency);
}
@Test(expectedExceptions = MyCustomException.class)
public void getPriceNonExistentSkuThrowsException() throws Exception {
// Set expectations on mocks.
expect(mockedDependency.getPriceBySku(BAD_SKU)).andReturn(null);
// Set mocks into testing mode.
replay(mockedDependency);
final BigDecimal price = systemUnderTest.getPrice(BAD_SKU);
}
@Test(expectedExceptions = RuntimeException.class)
public void getPriceDataAccessThrowsRuntimeException() throws Exception {
// Set expectations on mocks.
expect(mockedDependency.getPriceBySku(SKU)).andThrow(new RuntimeException("Fatal data access exception."));
// Set mocks into testing mode.
replay(mockedDependency);
final BigDecimal price = systemUnderTest.getPrice(SKU);
}
任意のアイデアみんな、何私は間違っている?
どうもありがとうございました!私は私のテストを書きました。 – dchucks