I seem to be having all kinds of problems trying to get NUint to play nice with a PCL library. My PCL library targets .NET 4.5, Silverlight 4 and higher, Windows Phone 7.5, Windows Store, Mono for Android and MonoTouch (the last two with Xamarin). However, when I try to add NUnit to the project via NuGet it looks like it gets added (nunit.framework is added to the references) but the NUnit namespace isn't available. If I try and add a using NUnit.Framework
, Visual studio underlines it and if I try and build I get an error about the NUnit
namespace can't be found along with this warning:
Warning 2 The primary reference "nunit.framework" could not be resolved because it has an indirect dependency on the framework assembly "mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" which could not be resolved in the currently targeted framework. ".NETPortable,Version=v4.0,Profile=Profile104". To resolve this problem, either remove the reference "nunit.framework" or retarget your application to a framework version which contains "mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089".
Can NUnit work with PCLs? The mvvm cross tutorials certainly seem to manage it.
I tried creating a separate project for testing (a regular class library) and I can add NUnit to that, but then I can't seem to add a reference to my PCL library (the one I want to test), so that doesn't help either.
Any ideas?
NUnit is a developing, open-source framework designed for writing and running tests in Microsoft . NET programming languages. NUnit, like JUnit, is a part of test-driven development (TDD), which is a piece of a bigger programming design paradigm known as Extreme Programming (in XP).
NUnit is an open-source unit testing framework for the . NET Framework and Mono.
The current version of NUnit is 3. It can be installed either from NuGet packages or from . NET Core CLI tool.
This argument has flaws but I will make it anyway...
Go ahead and write and run your unit tests in a .net 4.5 library and reference your PCL library from there. The goal of the unit test it to test the logic. Whilst it is true that some things may be different for the different PCL 'target versions' (methods not implemented etc), I suspect that testing your code this way will cover 99% of cases.
Besides, if you want a 'true' test of the logic, you need to get your unit tests running on the devices that you want to test...and then each version of the OS...and potentially different devices with different CPU's etc. How far do you want to go?
You mentioned that you couldn't add a reference to your PCL from the 'regular' test library...what sort of error do you get? I have been using this approach to test my PCL logic and it works like a charm, perhaps it is not perfect but for the 1% of cases where things are different on the device and things fail...I have an exception harness that logs to a server :-)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With