简体   繁体   中英

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. 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. ( Xamarin's documentation isn't that helpful, as they focus on view testing.)

I've added a new project to my solution by using the .NET -> Unit Library Project template. There's a default test in there called Test where I added a failure:

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. 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. 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).

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:

在此处输入图片说明

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM