mercredi 3 juin 2020

Any way to run one test inside another, and be able to see if child test passes?

I want to know if it's possible to somehow call one functional test inside another, and have the parent functional test be able to see if the child tests passes or not ? ... Please note that the parent and child tests are in different projects and although I can reference the child test's project in my project's CSPROJ file for read access, I cannot modify anything in the child test's project.

Something like this is what I'm after:

[TestClass]
public class ParentTests
{

    [TestMethod]
    public void Test_Parent()
    {
        var childTestPassed = RunAnotherTest(Test_Child);

        if(childTestRunResult == true)
        {
            // do something
        } else
        {
            // do something
        }
    }
}

... where Test_Child is the name of the child test method I want to run within my parent test.

I know very clearly that this is not the recommended testing methodology to use as tests need to be stateless, independent, modular with consistent results, however I have a very tricky scenario which requires me to do what I've stated above - there's no way around it. As I said, I do not have control over the child functional test source code, so if the above isn't possible then I'll have to copy paste the entire code of the child test, into my parent test, which I don't want to do as it's quite big and involves importing several classes, interfaces, etc., and I don't have working knowledge of that code.

In case if you still want to know why I'm asking this, please put a comment and I can answer.

Aucun commentaire:

Enregistrer un commentaire