Nunit 3 tests failing through resharper only
I am running a project in visual studio 2015. I added nuget packages for Nunit (v3.6.1) and Nunit.console as advised by the Nunit documentation.
I created a test class using the 'create unit tests' feature on the project class. The test methods within this class run fine through the default visual studio test explorer (and by clicking the codelens icon on each method) However, the resharper icons all show test failure and the unit test session window shows the reason as:
System.BadImageFormatException : Could not load file or assembly 'BaseProject, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. An attempt was made to load a program with an incorrect format.
I would understand if there was a problem with the project reference, however as I have said, the visual studio test runner is picking everything up fine. Can somebody shed some light on this for me? I'd of course much prefer to be using the resharper functionality rather than the default.
Please sign in to leave a comment.
Hello Anya-May
Please check what "Platform target" you have for each project (Project Properties | Build page). Seems like one project has "Any CPU" and the other has "x86" or something like this.
As a workaround you might try selecting "Force test to run in 32bit process" here ReSharper | Options | Tools | Unit Testing | General | Default platform architecture combobox.
By the way, is base project .NET Core? If so, there is https://youtrack.jetbrains.com/issue/RSRP-463943 request on YouTrack.
Thanks!
Hello and thankyou for your comment. Unfortunately I've seen this error before in other projects and am aware of that particular cause. The project I am referring to currently has every platform target set to the same thing (x86) as this particular program cannot run on 64 bit. (So I double checked this before posting this problem)
Also that particular problem would show up on compile (or run as I've sometimes found!) and the program runs fine and the test explorer/visual studio integrated tests run just fine:
However, if I try to run the exact same tests through the resharper model:
Which is why I'm thinking this is a resharper specific problem. Thanks for the workaround idea and I have tried it but unfortunately I get the exact same readout. Thankyou for trying to figure this out for me!
Ok, got the workaround working! Turns out I needed to use the 'options' dropdown box from the unit test sessions window to make the change as well as doing so in settings.
Would still be interested to know the source of this problem as nowhere else in my code is reporting an platform mismatch but can live with this. Thank you so much, at least now I can use resharper for my testing.
Anya-May,
Thanks for letting me know that the workaround helped you to run the tests via ReSharper Unit Test runner.
The only case, we have found when the issue happened, described in https://youtrack.jetbrains.com/issue/RSRP-463943: unit tests project has "Any CPU" and main project has x86. Why the issue happens in your solution if you do not have similar "Platform target" configuration - it is a good question for deeper investigation. Are you able to reproduce the similar behavior in a newly created project or send us the problem one?
Thanks!