question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Snapper.Json.Xunit does not work in Release builds

See original GitHub issue

(This is based on Snapper v1.3.1)

Since the XUnit integration uses StackTraces to find information about the test that is actually using it (see XUnitHelper.GetCallingTestInfo()), this cannot be used in “release” builds (i.e. any release that does not include debug symbols and/or uses extensive optimization).

As the “Remarks” section on the StackTrace documentation states:

StackTrace information will be most informative with Debug build configurations. By default, Debug builds include debug symbols, while Release builds do not. The debug symbols contain most of the file, method name, line number, and column information used in constructing StackFrame and StackTrace objects.

StackTrace might not report as many method calls as expected, due to code transformations that occur during optimization.

Running tests in a release configuration might not be the default use case, but I think it’s not very unusual either. Especially in CI servers, where you want to test what you deploy, building and testing the release configuration seems valid to me. (This is, in fact, how this issue bit me.)

It would be great if future versions of Snapper could use more robust ways to automatically gather the information that XUnitSnapper so conveniently provides.

A possible alternative might be the “caller information” attributes where the compiler fills in certain information about the source file containing the call site, in particular [CallerMemberName] and [CallerFilePath].

If release configuration cannot be supported (e.g. too much effort, or technically not feasible in general), it would be great if you could at least specify this as a known limitation in a prominent place (e.g. the README file).

Thanks for the work you put into this library already! It makes snapshot test really quite convenient 😃

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
theramiscommented, May 11, 2019

Decided to not do anything for now. Snapper throws a better error which lets the user know why it’s failing.

Its also mentioned in the FAQS on how they can solve the issue. https://theramis.github.io/Snapper/FAQS.html

0reactions
viceicecommented, May 10, 2019

A solution could be to include a props file to the package, with will set the Optimize flag to false

Read more comments on GitHub >

github_iconTop Results From Across the Web

Xunit Unit Tests will not run
To fix, as mentioned here, from the Visual Studio menu, go to Test -> Test Settings -> Default Processor Architecture and set that...
Read more >
theramis/Snapper: Bringing Jest-esque Snapshot testing to ...
Using Snapper the test would immediately fail since it's a change in the system and the developer should verify if the change was...
Read more >
Snapper 2.4.0
Snapper is a NuGet library which makes snapshot testing very easy in C#. Snapshot testing can simplify testing and is super useful when...
Read more >
Interactive Unit Testing with .NET Core and VS Code
In this issue, I continue discussing testing JavaScript in VS Code with an introduction to interactive testing in the context of .NET Core...
Read more >
deps.json not published for projects referenced for XUnit ...
Iam able to run the XUnit integration tests using Visual Studio. On Release build, the bin folder has both files - Xyz.Api.deps.json and...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found