简体   繁体   English

如何在Xamarin中的PCL代码上创建和运行测试?

[英]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上。

View -> Pads -> Unit Tests will bring up the unit testing window: 查看 -> 打击垫 -> 单元测试将打开单元测试窗口: 在此处输入图片说明

You can run your tests there by clicking Run All or by right clicking on a test suite then selecting Run Test , Debug Test etc: 您可以单击“全部运行”或右键单击测试套件,然后选择“运行测试” ,“ 调试测试”等,在此处运行测试

在此处输入图片说明

在此处输入图片说明

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用“时,我无法运行applicaton <ViewCell.ContextActions> 在Xamarin表格(PCL)上? - I can't run applicaton when using '<ViewCell.ContextActions>' on Xamarin Form (PCL)? 如何使用xamarin forme pcl解决方案在iOS上运行通知? - How can I get notifications to work on iOS, using xamarin forme pcl soluction? Xamarin PCL-如何将文件上传到FTP服务器或从FTP服务器下载文件? - Xamarin PCL - How can I upload/download a File to/from a FTP Server? 如何在Xamarin Studio中使用WCF服务在带有可移植类库(PCL)的本机应用程序中登录 - How can I consume wcf service for login in Native apps with Portable class library (PCL) in xamarin studio 如何在Xamarin跨平台应用程序中创建具有sqlite支持的PCL - How to create a PCL with sqlite support in a xamarin cross platform application 如何使用NUnit创建一个通用的BaseTest,我可以继承它并从基本运行中进行测试? - How can I create a generic BaseTest with NUnit that I can inherit from and have tests from the base run? 我可以在NUnit运行测试之前和之后执行代码吗? - Can I have code that executes before and after tests are run by NUnit? 如何使用ReSharper创建NUnit测试? - How can I create NUnit tests with ReSharper? 如果没有点击Xamarin PCL项目中的新字段保留键盘,如何在输入上一个字段后将焦点移动到下一个字段? - How can I move focus to next field after enterd previous field without click on new field retain keyboard in Xamarin PCL project? Xamarin Forms无法运行PCL项目 - Xamarin Forms Cannot run PCL project
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM