【发布时间】:2017-05-12 01:04:15
【问题描述】:
我无法找到有关如何对 .NET Standard 1.6 类库(可以从 .NET Core 项目进行引用)进行单元测试的最新文档。
这是我的 project.json 在我的库中的样子:
{
"supports": {},
"dependencies": {
"Microsoft.NETCore.Portable.Compatibility": "1.0.1",
"NETStandard.Library": "1.6.0",
"Portable.BouncyCastle": "1.8.1.2"
},
"frameworks": {
"netstandard1.6": {}
}
}
现在剩下的任务是能够创建某种可以进行单元测试的项目。目标是使用 xUnit,因为这似乎是 .NET Core 团队正在推动的。
我继续创建了另一个 .NET Portable 库项目,它的 project.json 如下所示:
{
"supports": {},
"dependencies": {
"Microsoft.NETCore.Portable.Compatibility": "1.0.1",
"NETStandard.Library": "1.6.0",
"xunit": "2.2.0-beta4-build3444",
"xunit.runner.visualstudio": "2.1.0"
},
"frameworks": {
"netstandard1.6": {
}
}
}
我在该项目中的测试类如下所示:
using USB.EnterpriseAutomation.Security.DotNetCore;
using Xunit;
namespace Security.DotNetCore.Test
{
public class AesEncryptionHelperTests
{
[Fact]
public void AesEncryptDecrypt()
{
var input = "Hello world!";
var encrypted = AesEncryptionHelper.AesEncrypt(input);
var decrypted = AesEncryptionHelper.AesDecrypt(encrypted);
Assert.Equal(input, decrypted);
}
}
}
当我继续构建该项目时,测试资源管理器看不到我的任何测试。
如何创建能够测试此库的单元测试?
【问题讨论】:
-
有人在 VS 2017 RTM 中发现了这一点吗?当我尝试测试 NetStandard 库时,找不到我的测试。我引用的是 xunit 和 xunit.runner.visualstudio 的 2.2 版。
标签: c# .net .net-core xunit.net project.json