Garbage Data Testing Integration

I installed integration testing using MSTest. My integration tests create fake data and paste it into the database (real dependencies). For each business object, I have a method that creates a "Fake" and inserts it into db:

public static EventAction Mock()
{
    EventAction action = Fixture.Build<EventAction>().Create();
    action.Add(false);
    AddCleanupAction(action.Delete);
    AppendLog("EventAction was created.");
    return action;
}

I clear all fakes in [AssemblyCleanup]:

public static void CleanupAllMockData()
{
    foreach (Action action in CleanUpActions)
    {
        try
        {
            action();
        }
        catch
        {
            AppendLog($"Failed to clean up {action.GetType()}. It is possible that it was already cleaned up by parent objects.");
        }
    }
}

Now I have a big problem. In my continuous integration environment (TeamCity), we have a separate database for testing, and it is cleared after each test run, but in my local environment, integration tests point to my local database. Now, if I canceled the test run for any reason, this leaves a bunch of garbage data in my local database, because CleanupAllMockData () is never called.

? MSTest.

+4
1

:

  • mock . .
  • db, .
+1

Source: https://habr.com/ru/post/1690709/


All Articles