How to test a PCL library the right way?

Hi there.

I'm building a PCL and I'd like to run its integration tests on real hardware.
The "run tests on desktop with NUnit and assume they work for all platforms" approach is a no-opt.

Meaning, I write test cases once and then use a platform specific runner.
It will be MonoTouch.NUnitLite or Andr.Unit respectively.,_testing,_and_metrics/touch.unit/

Is it possible with Xamarin?
Can Nunit Library Project template help me? Please guide me to a proper tutorial.

Thanks in advance.


  • AlexanderDodatkoAlexanderDodatko USMember

    File linking of test case classes may solve the problem of copy-pasting the code itself. Still, it seems to be a hot fix rather than a proper solution.

  • AlexanderDodatkoAlexanderDodatko USMember

    PCLs can not be tested themselves, they need to be run on a host.
    You can test them using the new Shared Project support on the beta.


    I'm going to try this suggestion after the weekend.

  • moljacmoljac HRBeta ✭✭✭

    I don't like argument I'll give because I do discuss this stuff all the time.

    There is thin line between types of testing unit or integration or... You are trying to use unit testing tool nunit for "integration tests on the hardware". OK there are variants of nunit for mobile platforms, but common code will fail because different platforms work differently. The simple example is how to interpret current_folder for android it is "/" and for other it is mostly current folder for the app.

    For small team it is not feasible for N platforms to have N unit testing projects and then even more integration testing projects.

    Thus "run tests on desktop with NUnit and assume they work for all platforms" - you test functionality of the classes and methods and try to "extract" location of the files and other platform specific stuff to another test project MonoTouch.NunitLite or Andr.Unit.

    I see no reason why PCL cannot be referenced from nunit project. It is "portable" and runs on desktop .net/mono right?

    The reason I usually avoid nunitLites is because they all need to launch emulator or device. Just to see that my class and methods are working ok? (Assuming no bugs) I could do it on desktop and I mostly do. Like suggested in the doc you have referenced.

    Shared Project or PCL is matter of taste and use case, one produces single assembly and the other produces for N platforms N assemblies. Both approaches enforce least-denmonator philosophy. Write code that will run on all platform as common project (PCL or shared) and then add platform specific stuff as you wish.

    PCL and shared are just deployment/packaging (low level) choices for me.

    I could (before PCL were stable) achieve the same with source sharing - desktop (client profile) dll acting as common/PCL/shared and platform specific dlls with platform specific code. Whether platform specific dlls reuse code from shared/common dll through file-sharing or referencing (project or dll) is the matter of taste.

    I like file linking because I have common code in desktop (client profile) dll and deltas - platform specific in platform project and I really see specific things in specific projects.

    For unit testing - in my case - hook up nunit (desktop) on common (dekstop dll) and you'llbe fine for 90-95% of the time. For other 5-10% hook nunitlite to platform specific dlls and test only those deltas....

    I'm not sure if this helps all this stuff is new and we all are searching for the right answer (42), the question is problem. That is the reason everyone runs towards new features (shared libs) as soon as they come out and those are not revolutionary. I mean project Prism and ProjectLinker are 6+ years old when Microsoft played with "cross platform" code sharing and reusability in their Patterns and Practices.

    They left great tools behind


  • You might look at It has tests for the different platforms.

  • AlexanderDodatkoAlexanderDodatko USMember

    @DerekBeattie.6675‌ , the SQLite.Net-PCL tests seem to use file linking approach when a single *.cs file can be included to multiple *.csproj files.

    File linking of test case classes may solve the problem of copy-pasting the code itself. Still, it seems to be a hot fix rather than a proper solution.

    Thanks anyway.

  • AlexanderDodatkoAlexanderDodatko USMember

    Both approaches enforce least-denmonator philosophy

    So, the question was :

    AS a library vendor
    I want to write my integration tests (for the  "least-denominator") once 
    AND run them on each platform
    SO THAT I can guarantee to my users the library works on their platform as expected.

    I understand it's ok to use a desktop version of NUnit for unit testing that check the logic.

    However, the "desktop only" approach is not acceptable for integration tests. @moljac‌, if you know any better tools for portable libraries integration testing please share a link.

  • AlexanderDodatkoAlexanderDodatko USMember

    Shared Project seems to look less ugly than file linking approach.
    It's pretty similar but portable test cases are gathered in a separate *.csproj that neither builds, nor references other assemblies.

    Still, it's not supported by M$ Visual Studio yet.

Sign In or Register to comment.