1

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)));
        }
Pascal
  • 12,265
  • 25
  • 103
  • 195

1 Answers1

8

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.

Community
  • 1
  • 1
Lester
  • 4,243
  • 2
  • 27
  • 31
  • "Is there a specific..." 1.) Yes there is. We run all our preconditions normally in a setup method with [Setup] attribute which is called before every test. We have no individual test data for a method (the exception is in that sample I posted...) So how does our approach fit into the AAA pattern? "...Note:..." 2.) My deleteRelease method does not return anything because why should it fail? It can only be deleted from the author itself so no concurrency here. – Pascal Feb 27 '12 at 21:03
  • Well, since AAA is focused on unit tests and you're doing an integration test, you should use it more as a rough guideline and not get too caught up on details. Either putting it in the arrange block or just not have one if you're using a [Setup] method should be fine. – Lester Feb 27 '12 at 21:17
  • 1
    Also, my note is still valid. "You ask why should it fail?" and I can argue that in some systems the expected behaviour is to fail for invalid input while in your system the expected behaviour may be to do nothing. – Lester Feb 27 '12 at 21:19
  • 1
    of course your note/care is valid :) Cool you work where Marlon works :P – Pascal Feb 27 '12 at 21:24