The type 'TestContext' is defined in an assembly that is not referenced. You must add a reference to assembly 'Microsoft.VisualStudio.QualityTools.UnitTestFramework

vrushali 1 Reputation point
2021-11-09T18:09:04.01+00:00

we need to access test context created by specflow project in one of the method , so we have written below code in specflow hooks.

    [BeforeScenario]
    public void BeforeScenario( microsoft.visualstudio.testtools.unittesting.TestContext  context)
    {
        InitializeSpecflow(context);
    }

InitializeSpecflow( microsoft.visualstudio.testtools.unittesting.TestContext context)
{

//Logic for context.TestName execution logic
}

but , when we pass specflow test context to method even if both test context are of same type (i.e microsoft.visualstudio.testtools.unittesting.TestContext )
it gives error as "The type 'TestContext' is defined in an assembly that is not referenced. You must add a reference to assembly 'Microsoft.VisualStudio.QualityTools.UnitTestFramework"

Developer technologies Visual Studio Testing
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. PengGe-MSFT 3,381 Reputation points
    2021-11-10T03:23:29.613+00:00

    Hi, @vrushali

    Welcome to Microsoft Q&A!

    You can try to add this nuget package: Microsoft.UnitTestFramework.Extensions

    Sincerely,
    Peng
    *
    If you have extra questions about this answer, please click "Comment". If the answer is the right solution, please click "Accept Answer" and kindly upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.