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.
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.
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:
Note: These tests are totally independent of Xamarin.Android|iOS|Mac
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 TestingXamarin.Mac
Unit Testing via GUIUnit
Xamarin.Android
Setup and AutomatingA 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 ! :)
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