考虑到这是对我的数据库的集成测试,使用 Arrange Act 断言 Arrange“部分”中应该包含什么?
private void Delete_Release_Test_Data(string conString)
{
UnitTestHelper.PrepareData(new[] { "ReleaseId" }, new object[] { 100 });
UnitTestHelper.InsertPreparedData(conString, RELEASE_TABLE);
}
[Test]
public void Delete_Release(string conString)
{
Delete_Release_Test_Data(conString);
// ARRANGE
// What should I put here ???
// ACT
IReleaseDataProvider provider = new ReleaseDataProvider();
provider.DeleteRelease(100);
// ASSERT
Assert.IsTrue(UnitTestHelper.HasNoData(conString, string.Format("SELECT * FROM {0}", RELEASE_TABLE)));
}
最佳答案
是否有特定原因导致第一行 Delete_Release_Test_Data(conString)
未安排?来自 this link关于安排行为断言:
Each method should group these functional sections, separated by blank lines:
- Arrange all necessary preconditions and inputs.
- Act on the object or method under test.
- Assert that the expected results have occurred.
插入有效的测试数据是这个测试的前提条件,这意味着它应该放在 Arrange 部分下。
注意:您还可以将此测试重命名为 Delete_Release_When_Exists
,然后创建一个测试 Delete_Release_When_Doesnt_Exist
以验证抛出或返回正确的异常值是正确的。
关于c# - 在集成测试中使用 Arrange Act Assert 模式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9470795/