Xamarin (Android) Unit Tests in Visual Studio 2017 - c#

I'm using Visual Studio 2017 to develop Xamarin Android application. I want to add simple unit tests of logic only. For that purpose, I tried adding "Unit Test App (Android)" or "Class Library (Android)" projects with unit tests and none of them work.
Unit Test App (Android)
I add new project to my solution of type "Unit Test App (Android)". Generated project contains TestsSample class with sample tests, but I have no idea how to launch them. I have ReSharper installed, but when right clicking on the project/class I don't have option to run the tests.
When I go to "Test" -> "Run" -> "All tests", the solution is built, but nothing more happens.
Class Library (Android) with nUnit
The other trial was to add new project of type "Class Library (Android)" to the solution. After, I installed nUnit nuget package (install-package nunit which installed package 'nunit.3.6.1' with respect to project 'MoneyBack.Tests', targeting 'MonoAndroid,Version=v6.0'), installation was successful.
I added the following class:
using NUnit.Framework;
namespace MoneyBack.Tests
{
[TestFixture]
public class Class1
{
[Test]
public void SampleTest()
{
Assert.IsTrue(true);
}
}
}
Now when right-clicking on the tests project I see ReSharper's option "Run Unit Tests", so I clicked it and got the following exception:
Am I doing something wrong ? Or it's the issue with VS2017 ? I don't know if I should install VS2015 back or there is some solution. Thanks for your help!

There are three basic levels of testing:
The classic unit testing of pure .Net/Mono code via xUnit|NUnit
Nothing new here, this is the same testing that .Net programmers have been doing all long and has nothing to do with the Xamarin platform frameworks
Note: These tests are totally independent of Xamarin.Android|iOS|Mac
On platform testing (including platform features)
Note: There are multiple on device testing wrappers for NUnit, XUnit, etc... Xamarin includes a NUnitLite version that runs on Android and iOS and that provide a device specific UI to run those tests. Xamarin has templates that create a Unit Test App project for Android or iOS.
Note: These tests can include platform dependent features (Networking, Bluetooth, GPS, SMS, etc... but no GUI related tests) and can also reference Nunit [Test]s written in PCL-based assemblies or platform-specific libraries.
Xamarin.iOS Unit Testing
Xamarin.Mac Unit Testing via GUIUnit
Xamarin.Android Setup and Automating
Alternatives to NUnitLite:
xUnit.net Runners for Devices
NUnit test runners for Xamarin and mobile devices
UI Testing
A Casabash/Appium/... driven tests of the UI elements in your application and their reaction to input (touch) events.
Test Cloud/Mobile Center and/or other local, public or private mobile test clouds
Xamarin Test Cloud

Test are run from the device itself not directly from the code as we are used to. Do this:
1. set you android project as VS startup project
2. Select the harware or simulator that you want to execute the unit test project
3. Run it
4. The unit test project will be deployed and executed in the device.
5. Tap on the line with the project name. The available tests will appear. Tap each one for execution and debug ! :)

You need to install nUnit 2.6.X for using xamarin.UItest.
nUnit 3 is not supported.

Related

Is it possible to fake other OS platforms for unit tests?

I make cross-platform and multi platform tools. They for example load different modules depending on the runtime platform.
Obviously, I won't be able to fully test them in Visual Studio on Windows, but I could at least test if they detect the runtime platform correctly and if they load appropriate modules.
The system checks are pretty standard:
if (RuntimeInformation.IsOsPlatform(OSPlatform.Linux)) { /* do the Linux thing */ }
I test Linux code just by publishing a Linux executable (as standard console application)
and then just output the test results to the console.
It would be cool if I would be able to add some XUnit tests to my Visual Studio solution
that test some of this code.

Unable to add a reference to unit test project

I am setting up a unit test bench and as an example exercise created a simple calculator. I'd like to develop test cases for it. When I try to add the project reference to the unit test project an error "Enable to add a reference to project 'Calculator'" appears. No reason or corrective action is provided
Initially I thought the reason was because developer mode was not enabled on my computer. But the problem persists with developer mode on also.
This issue has been resolved. I created a unit test project in .net instead of universal windows application and it worked

Unit testing a c# Windows 10 IoT core application (Error : DEP0700)

I'm trying to write some unit tests for a windows 10 IoT core application I have written for my Raspberry Pi (arm architecture). I have added a new Unit Test App project to my solution and added namespace reference. When I try to run the tests from test explorer however, I get:
Error : DEP0700 : Registration of the app failed. Windows cannot install package 29113fce-56cd-4094-9a21-ee91498c14b2 because the package requires architecture ARM, but this computer has architecture x64.
Deploying the test app to the remote machine (Pi) results in Tests running printing to the screen, however nothing happens. The tests still don't run on my machine and when i select tests on the output console it displays nothing.
Does anyone have any experience unit testing a Windows 10 IoT core application or can see anything immediately obvious I've done wrong?
There are two ways you can run the tests:
Run the whole application in local machine (x86) and also the tests. If the app is UWP, and does not use much of RPi-specific functionality, this should be the easiest way.
Do the remote testing, with application running on RPi. To do that, you need to install Remote Debugging Tools for Visual Studio on the target RPi board. This article describes it in more detail.

How to set up Unity Test Tools on Unity 5

I'm trying to figure out how to make it work. The documentation is slim to say the least on this important topic.
The small amount of tutorials I found make reference to options not even present when I open the tool. I don't see the Unit Test Runner, just the Integration Test runner. (version 5.3.1f1)
How to add a test? How to run it?
Integration Test runner allows you to add a test, but I was unable to find how to write the actual test.
It's sad that there's almost no documentation on this anywhere, or at least I haven't found it.
The Unity Test Tools are already included in Unity starting with Version 5.3. Even without downloading the Unity Test Tools from the Asset Store you should be able to find the "Editor Test Runner" in the Window menu. This is basically the Unit Test runner. For other features such as Assertions, Integration tests etc. you still need the Unity Test Tools bundle from the Asset Store.
The test tools use NUnit internally, so you can write tests using the standard NUnit API as described here http://www.nunit.org/index.php?p=quickStart&r=2.6.3.
There is also a Unity tutorial video here: https://unity3d.com/learn/tutorials/modules/beginner/live-training-archive/test-tools.
Make sure to put your Tests into an Editor folder.
Also note that some features like Assertions are not supported for Windows Store Apps and you won't even be able to build for this platform as long as you have those libraries in your project.

Integration of automated testing in hudson using selenium framework

I'm new to web development and web testing. And I want to use Hudson in my continous integration and for my automated testing using selenium. How can I integrate the selenium in hudson, so that everytime I build using hudson, it will automatically execute the automated testing in selenium? What application should I install? By the way I'm using ubuntu as my OS.
I'm building my webapp using asp.net and C#.
Please advise.
Thanks.
You would invoke the tests like you would for your normal unit tests. Assuming that you are creating your tests to be run with NUnit then you will need to make sure that that is installed.
Setting up your Selenium project, like a normal class library project, that builds a dll that can run your tests should suffice.
You can Integrate your Selenium-TestNG/Nunit Framework with Maven, Maven build path you can give in Jenkins/Hudson.

Categories