[英]How can I create and run tests on PCL code in Xamarin?
This seems relatively simple but I'm not able to find a direct step by step guide anywhere. 这似乎相对简单,但是我无法在任何地方找到直接的逐步指南。 I have a simple PCL class I've created that is platform independent and I'd like to write a unit test for it.
我有一个简单的PCL类,它是独立于平台的,我想为此编写一个单元测试。 Right now I'm stuck with my test code in an iOS view controller and can only run it by running the app in the simulator.
现在,我将测试代码停留在iOS视图控制器中,并且只能通过在模拟器中运行应用程序来运行它。 ( Xamarin's documentation isn't that helpful, as they focus on view testing.)
( Xamarin的文档没有太大帮助,因为它们专注于视图测试。)
I've added a new project to my solution by using the .NET -> Unit Library Project
template. 我已经使用
.NET -> Unit Library Project
模板向解决方案中添加了一个新项目。 There's a default test in there called Test where I added a failure: 有一个默认的测试叫做Test,我在其中添加了一个失败:
using NUnit.Framework;
using System;
namespace Tests
{
[TestFixture ()]
public class Test
{
[Test ()]
public void TestCase()
{
Console.WriteLine ("this is a test");
Assert.Fail ("this should fail");
}
}
}
I can't for the life of me figure out how to run this test from within the Xamarin IDE. 我一辈子都想不通如何在Xamarin IDE中运行此测试。 I'd assume I could right-click on either my new Test project and run the whole thing or right-click on this specific class and run it directly.
我假设我可以右键单击我的新Test项目并运行整个程序,或者右键单击此特定类并直接运行它。 When I right-click on the Test project, I see the following options:
右键单击“测试”项目时,我看到以下选项:
My Test project structure looks like: 我的测试项目结构如下:
If there's no other option, I would accept an answer that tells me how to run this on the command line. 如果没有其他选择,我将接受一个答案,告诉我如何在命令行上运行它。
FWIW, I'm on a Mac running Xamarin Studio 5.9.7 (build 9). FWIW,我在运行Xamarin Studio 5.9.7(内部版本9)的Mac上。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.