运行包含在 .NET Standard 1.6 库中的 xunit 测试 [英] running xunit tests included in a .NET Standard 1.6 library

查看:30
本文介绍了运行包含在 .NET Standard 1.6 库中的 xunit 测试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚在 Visual Studio 2017 中创建了一个 netstandard 库并添加了对 xunitxunit.runner.visualstudio 的引用,但 VS 测试资源管理器和 Resharper 2017 EAP 3 是不承认任何测试.我见过:

编辑

感谢您的回答,我取得了一些进展.

添加

<!-- ... 和 ...--><项目组><Service Include="{82a7f48d-3b50-4b1e-b82e-3ada8210c358}"/></项目组>

没有影响.只有当我将 TargetFramework 更改为 netcoreapp1.1 时,VS 才发现测试并可以运行它们.使用 netstandard1.6 时,测试资源管理器保持为空.但我不想要一个 netcore 应用程序.我想要一个 .NET 标准库.

解决方案

我知道这是一个较老的问题,但我遇到了同样的问题 - 编写在 Visual Studio 测试运行器和 Xamarin.iOS/Droid 中运行的 xunit 测试.对于 netstandard,我最终做的是创建一个 .NET Core 2.0 单元测试项目,创建 Xamarin.* 测试应用程序(并为单元配置它们),并创建一个共享项目而不是 netstandard图书馆.这对我有用.

我的测试项目结构是:

  • Project.Tests.Droid(Droid UI 项目)
  • Project.Tests.iOS(iOS UI 项目)
  • Project.Tests.Unit(VS 单元测试项目)
  • Project.Tests(共享项目)

我所有的测试都在 Project.Tests 中.

I just created a netstandard library in Visual Studio 2017 and added references to xunit and xunit.runner.visualstudio, but the VS Test Explorer and Resharper 2017 EAP 3 are not recognizing any tests. I've seen: Unit testing a .NET Standard 1.6 library but project.json is gone and csproj is back in place.

What do I have to do, to be able to run the unit tests included in a netstandard library?

Library.csproj

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>netstandard1.6</TargetFramework>
  </PropertyGroup>
  <ItemGroup>
    <PackageReference Include="xunit" Version="2.2.0" />
    <PackageReference Include="xunit.runner.visualstudio" Version="2.2.0" />
  </ItemGroup>
</Project>

Test.cs

namespace ClassLibrary2
{
    public class Class1
    {
        [Fact]
        public void RescharperShouldRunTest()
        {
            Assert.True(true);
        }
    }
}

Edit

Thanks to the answers I made some progress.

Adding

<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.0.0" />  
<!-- ... and ...  --> 
<ItemGroup>
    <Service Include="{82a7f48d-3b50-4b1e-b82e-3ada8210c358}" />
</ItemGroup>

did have no impact. Only if I change the TargetFramework to netcoreapp1.1 VS discovered the test and could run them. With netstandard1.6 the Test Explorer remains empty. But I don't want a netcore app. I want a .NET standard library.

解决方案

I know this is an older question, but I have had the same problem - writing xunit tests that run in the Visual Studio test runner and Xamarin.iOS/Droid . For netstandard what I ended up doing was creating a Unit test project that was .NET Core 2.0, creating the Xamarin.* test applications (and configuring them for unit), and creating a Shared project instead of netstandard library. This worked for me.

My test project structure is:

  • Project.Tests.Droid (Droid UI project)
  • Project.Tests.iOS (iOS UI project)
  • Project.Tests.Unit (VS Unit test project)
  • Project.Tests (shared project)

All my tests are in Project.Tests.

这篇关于运行包含在 .NET Standard 1.6 库中的 xunit 测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆