5

What causes the message "Approvals is not set up to use your test framework."?

We have an ApprovalTests-based unit test that is failing in a nightly remote team build with the following exception:


Test method Test_CanvasModeConverters threw exception:
System.Exception: Approvals is not set up to use your test framework.
It currently supports [NUnit, MsTest, MbUnit, xUnit.net] To add one use ApprovalTests.StackTraceParsers.StackTraceParser.AddParser() method to add implementation of ApprovalTests.StackTraceParsers.IStackTraceParser with support for your testing framework. To learn how to implement one see http://blog.approvaltests.com/2012/01/creating-namers.html

This unit test passes fine in a local VS2010 unit test run (i.e., mstest). It also passes fine in a remote team "checkin" build (that is run with every code checkin).

We have logged some diagnostic information at the beginning of the test to identify the ApprovalTests.dll assembly that is in-play...

--------------------
ApprovalTests, Version=1.21.4657.21485, Culture=neutral, PublicKeyToken=11bd7d124fc62e0f:
CodeBase = file:///E:/BldSrc/27/305/TestResults/NightlyBuild/Client[2]/Out/ApprovalTests.DLL
FullName = ApprovalTests, Version=1.21.4657.21485, Culture=neutral, PublicKeyToken=11bd7d124fc62e0f
GlobalAssemblyCache = False
ImageRuntimeVersion = v4.0.30319
Location = E:\BldSrc\27\305\TestResults\NightlyBuild\Client[2]\Out\ApprovalTests.dll
Company Name = 
Assembly Product = ApprovalTests
--------------------

Here is the stack trace...

ApprovalTests.StackTraceParsers.StackTraceParser.Parse(StackTrace stackTrace)
ApprovalTests.Namers.UnitTestFrameworkNamer..ctor()
ApprovalTests.Approvals.<.cctor>b__11()
ApprovalTests.Approvals.GetDefaultNamer()
ApprovalTests.Approvals.Verify(IApprovalWriter writer)
ApprovalTests.Approvals.Verify(String text)
ApprovalTests.Combinations.CombinationApprovals.VerifyAllCombinations[A,B,C,D,E,F,G,H,I](Func`10 processCall, String format, Func`2 resultFormatter, IEnumerable`1 aList, IEnumerable`1 bList, IEnumerable`1 cList, IEnumerable`1 dList, IEnumerable`1 eList, IEnumerable`1 fList, IEnumerable`1 gList, IEnumerable`1 hList, IEnumerable`1 iList)
ApprovalTests.Combinations.CombinationApprovals.VerifyAllCombinations[A,B,C,D,E,F,G,H,I](Func`10 processCall, String format, IEnumerable`1 aList, IEnumerable`1 bList, IEnumerable`1 cList, IEnumerable`1 dList, IEnumerable`1 eList, IEnumerable`1 fList, IEnumerable`1 gList, IEnumerable`1 hList, IEnumerable`1 iList)
ApprovalTests.Combinations.CombinationApprovals.VerifyAllCombinations[A,B](Func`3 processCall, IEnumerable`1 aList, IEnumerable`1 bList)

4 Answers4

4

As Graham said:

"Approvals Tests infers the name the approval file by walking the stack trace to get the test method name."

Most likely, I would suggest that your compiler might be removing (inlining) the actual test method. You can prevent this by method with the annotation

[MethodImpl(MethodImplOptions.NoInlining)]

Or, and I think this is the best option, turn off the feature entirely in your compiler options (unchecking the optimize code button in project properties)

llewellyn falco
  • 2,281
  • 16
  • 13
4

I made the following change to the project containing my test code and these errors were eliminated:

  1. Disable Code Optimization as suggested by Llewellyn
  2. In Advanced Build Settings, set "Debug Info" to "Full". It was set to pdb-only for Release builds in my project.

Again, I only had to make these changes to the project containing my tests.

Also, I tested the annotation suggested by Llewellyn and it worked too.

ain
  • 22,394
  • 3
  • 54
  • 74
jerryo
  • 41
  • 1
2

FWIW, I saw this problem when my test method was using a [TestCase(...)] attribute with no [Test]

[TestCase("example")]
public void Broken_Test(string parameter) {
  //...
}

Adding the [Test] attribute solved the problem

[Test]
[TestCase("example")]
public void Working_Test(string parameter) {
  //...
}
Steve Greatrex
  • 15,789
  • 5
  • 59
  • 73
1

Approvals Tests infers the name the approval file by walking the stack trace to get the test method name.

Your stack trace does not have your test name in it which could mean;

  • that you have not included the full stack trace which would contain the relevant information to answer you question
  • or your test is not picking up the stack trace info it needs due to a missing pdb perhaps?
Graham Ambrose
  • 1,891
  • 2
  • 13
  • 17