Visual Studio 2017中的Xamarin(Android)单元测试 [英] Xamarin (Android) Unit Tests in Visual Studio 2017
问题描述
我正在使用Visual Studio 2017开发Xamarin Android应用程序。我只想添加逻辑的简单单元测试。为此,我尝试添加带有单元测试的单元测试应用程序(Android)或类库(Android)项目,但它们都不起作用。
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.
我将新项目添加到类型为单元测试应用程序(Android)的解决方案中。生成的项目包含带有示例测试的 TestsSample
类,但是我不知道如何启动它们。我已经安装了ReSharper,但是右键单击项目/类时,我没有选择运行测试。
当我转到测试->运行->所有测试时,解决方案已构建,但是什么也没有发生。
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.
另一个试验是向解决方案中添加类型为类库(Android)的新项目。之后,我安装了nUnit nuget软件包( install-package nunit
),该软件包针对项目 MoneyBack.Tests安装了软件包 nunit.3.6.1,目标是 MonoAndroid,Version = v6.0'),则安装成功。
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.
我添加了以下类:
using NUnit.Framework;
namespace MoneyBack.Tests
{
[TestFixture]
public class Class1
{
[Test]
public void SampleTest()
{
Assert.IsTrue(true);
}
}
}
现在在右键单击时在测试项目中,我看到了ReSharper的选项运行单元测试,因此我单击了它并得到以下异常:
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:
难道我做错了什么 ?还是VS2017的问题?我不知道是否应该重新安装VS2015或有一些解决方案。谢谢您的帮助!
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:
- 这里没有什么新鲜的东西,这与.Net程序员长期以来所做的测试相同并且与Xamarin平台框架无关
注意:这些测试与完全不相关 Xamarin.Android | iOS | Mac
Note: These tests are totally independent of Xamarin.Android|iOS|Mac
注意: NUnit,XUnit等的设备测试包装器。Xamarin包含一个 NUnitLite
版本,该版本可在 Android
和<$上运行c $ c> iOS 并提供设备特定的UI来运行这些测试。 Xamarin的模板可为Android或iOS创建 Unit Test App
项目。
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.
注意:这些测试可以包含平台相关的功能(网络,蓝牙,GPS,SMS等...,但不包括与GUI相关的测试),还可以引用用PCL-编写的Nunit [Test]
基于程序集或平台特定的库。
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 viaGUIUnit
Xamarin.Android
Setup and Automating
- xUnit.net Runners for Devices
- NUnit test runners for Xamarin and mobile devices
由Casabash / Appium / ...驱动的应用程序中UI元素测试及其对输入(触摸)事件的反应。
A Casabash/Appium/... driven tests of the UI elements in your application and their reaction to input (touch) events.
-
测试云/ Mobile Center和/或其他本地,公共或私有移动测试云
Test Cloud/Mobile Center and/or other local, public or private mobile test clouds
这篇关于Visual Studio 2017中的Xamarin(Android)单元测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!