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
注意:有多个用于 NUnit、XUnit 等的设备测试包装器... Xamarin 包括一个在 Android
和 iOS<上运行的
NUnitLite
版本/code> 并提供特定于设备的 UI 来运行这些测试.Xamarin 具有为 Android 或 iOS 创建单元测试应用
项目的模板.
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]
s-基于程序集或特定于平台的库.
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
Casabash/Appium/... 驱动测试应用程序中的 UI 元素及其对输入(触摸)事件的反应.
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
这篇关于Visual Studio 2017 中的 Xamarin (Android) 单元测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!