2

I have built an Integration Test as a Visual Studio 2017 test project. This project will be run as a VSTS Build step.

Specifically, I am testing a database (PostgreSQL) provisioning app's correct function.

This means that this unit test will be using the Provisioning API to create a database and a database user in the database server, and the test will also be validating the correct structure of the database's schema, tables, and columns.

This results in the database server containing several databases constructed only from the integration test running.

It is planned that any failed databases will remain in the server so that they can be dissected for all errors, but we have no need to keep the successfully tested DB's.

My current problem is that since the test is in a Unit Test Project, the test methods run their asserts, and it's done.

How can I trigger a script to drop the database from the Postgres server when my Integration Test passes as 100%?

I only have ideas on what to do. Do I run an additional VSTS build step after the test step to run the script? Or do I have my test methods return a bool, and gather up the bools at the end of the project in a method that would run the script?

gunr2171
  • 16,104
  • 25
  • 61
  • 88
as.beaulieu
  • 464
  • 1
  • 10
  • 26

3 Answers3

3

From the perspective of a QA and Integration Testing, in NUnit (and others) there are Setup and Teardown steps that are executed before and after every test. You could put something in the Teardown step to confirm the test passed and if so call a script to drop the table.

    [TearDown]
    public void CleanUp()
    {
        if (TestContext.CurrentContext.Result.Outcome.ToString().Equals("Passed")
        {
            // Run Script to Drop Table
            // Confirm Table Dropped
            // Close Driver
            driver.Close();
            Console.WriteLine("Table Drop Confirmed and Driver Closed.");
        } else {
            Console.WriteLine("Test did not pass, Table not dropped.");
            driver.Close();
            Console.WriteLine("Driver Closed.");
        }
    }
LoflinA
  • 350
  • 4
  • 19
  • This is exactly what I'm looking for. I'm already using NUnit, and I'm not looking to change the best practice for Unit Tests (By giving them a return type), nor was I looking to make a whole other program or scripts in VSTS in addition to running this Integration Test. Great option I can add to what I already have and don't have to make anything extra. Thanks. – as.beaulieu Jan 19 '18 at 20:10
1

This might solve your problems: NUnit - Is it possible to check in the TearDown whether the test succeeded?

NUnit provides a way to access it's test run result, so you can check for success/failure and then perform a cleanup or skip it.

Petras Purlys
  • 1,093
  • 6
  • 18
0

In the testing frameworks that I’ve used, the asserts work by throwing exceptions when they fail. Execution of the test ends at that point. If you drop the table at the end of the test, after the assert, it wouldn’t run if the test failed (as execution would stop at the failed assert), but would run if the test passed.

Erresen
  • 1,923
  • 1
  • 22
  • 41
  • My concern with this, is that I have many test methods because I'm asserting against many conditions. Since I can't control the order in which my test methods run, how do I determine which method to run this in? – as.beaulieu Jan 19 '18 at 20:54