approvals / ApprovalTests.Net

ApprovalTest verification library for .Net
Other
570 stars 109 forks source link

Could Not Detect Test Framework - On async/await Nunit tests #236

Closed tharishreddy closed 4 years ago

tharishreddy commented 6 years ago

Approval Tests Nuget version - 3.0.14 The below code throwing an exception:

[Test]
[UseReporter(typeof(DiffReporter), typeof(NUnitReporter))]
public async Task Abc()
{
    await Task.Delay(1);
    Approvals.Verify("abc");
}

System.Exception : Could Not Detect Test Framework

Either: 1) Optimizer Inlined Test Methods

Solutions: a) Add [MethodImpl(MethodImplOptions.NoInlining)] b) Set Build->Optimize Code to False & Build->Advanced->DebugInfo to Full

or 2) Approvals is not set up to use your test framework. It currently supports [NUnit, MsTest, MsTest-DataTest, xUnit.net, xUnit.extensions, xUnit2.net, Machine.Specifications (MSpec)]

Solution: To add one use ApprovalTests.Namers.StackTraceParsers.StackTraceParser.AddParser() method to add implementation of ApprovalTests.Namers.StackTraceParsers.IStackTraceParser with support for your testing framework. To learn how to implement one see http://blog.approvaltests.com/2012/01/creating-namers.html

The below code works without any exception

[Test]
[UseReporter(typeof(DiffReporter), typeof(NUnitReporter))]
public async Task Abc()
{
    var task = Task.Delay(1);
    task.Wait();
    Approvals.Verify("abc");
}
SimonCropp commented 6 years ago

have u tried any of the suggestions?

if yes, can u add the contents of csproj

tharishreddy commented 6 years ago

Yes, tried solution-1 by adding [MethodImpl(MethodImplOptions.NoInlining)]. Still same issue. For solution-2, we are already using Nunit framework, which is currently supported by ApprovalTests

tharishreddy commented 6 years ago

As a workaround The below code works without any exception

[Test] [UseReporter(typeof(DiffReporter), typeof(NUnitReporter))] public async Task Abc() { var task = Task.Delay(1); task.Wait(); Approvals.Verify("abc"); }

SimonCropp commented 6 years ago

and have you done

Set Build->Optimize Code to False
& Build->Advanced->DebugInfo to Full
tharishreddy commented 6 years ago

Yes, correct.

SimonCropp commented 6 years ago

in that case can you upload, to a new github repository, a small solution that reproduces the issue

tharishreddy commented 6 years ago

uploaded a sample here - https://github.com/tharishreddy/AppTest

jawn commented 5 years ago

Additional note: the error message reported by the OP contains a link to a blog post that refers to a broken and outdated link: http://approvaltests.svn.sourceforge.net/viewvc/approvaltests/trunk/projects/ApprovalTests/DotNetApprovals/ApprovalTests/Namers/UnitTestFrameworks/NUnitStackTraceParser.cs?revision=345&view=markup