Search code examples
c#unit-testingintegration-testingarrange-act-assert

Using the Arrange Act Assert pattern with Integration Tests


Using the Arrange Act Assert what should be in the Arrange "section" considering that this is an integration test on my database?

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)));
        }

Solution

  • Is there a specific reason why the first line Delete_Release_Test_Data(conString) isn't under arrange? From this link on Arrange Act Assert:

    Each method should group these functional sections, separated by blank lines:

    1. Arrange all necessary preconditions and inputs.
    2. Act on the object or method under test.
    3. Assert that the expected results have occurred.

    Inserting valid test data is a precondition of this test which means that it should be placed under the Arrange section.

    Note: You can also rename this test to Delete_Release_When_Exists and then also create a test Delete_Release_When_Doesnt_Exist to verify the correct exception is thrown or return value is correct.