mardi 5 mai 2015

How do I Execute Code after a Test failed

I am Creating Unit Tests for a Library. This Library Connects to a Datasource and then I am doing some testing Stuff afterwards the Datasource will be disconnected.

If one of the Tests fails, the Method is Terminated and I dont get to execute the Disconnection Function.

Here's a Sample to understande the above description:

[TestMethod]
public void Test()
{
    var datasourceObject = new DatasourceObject("location-string");
    datasourceObject.Connect();

    // Do some Stuff with Asserts

    datasourceObject.Disconnect(); // must be executed
}

Is There any Bestpractice to achieve that?

Aucun commentaire:

Enregistrer un commentaire