gpt4 book ai didi

c# - VS2017 .NET Standard 库中的单元测试内部方法

转载 作者:IT王子 更新时间:2023-10-29 03:34:03 24 4
gpt4 key购买 nike

我目前正在通过创建 .NET Standard 1.6 库来使用最新的 Visual Studio 2017 Release Candidate。我正在使用 xUnit 对我的代码进行单元测试,想知道您是否仍然可以在 VS2017 中测试内部方法。

我记得你可以在 VS2015 的 AssemblyInfo.cs 类中添加一行,使指定的项目能够看到内部方法:

[assembly:InternalsVisibleTo("MyTests")]

由于 VS2017 .NET Standard 项目中没有 AssemblyInfo.cs 类,我想知道您是否仍然可以对内部方法进行单元测试?

最佳答案

根据 .NET docs for the InternalsVisibleToAttribute :

The attribute is applied at the assembly level. This means that it can be included at the beginning of a source code file, or it can be included in the AssemblyInfo file in a Visual Studio project.

换句话说,您只需将它放在您自己任意命名的 .cs 文件中,它应该可以正常工作:

// some .cs file included in your project
using System.Runtime.CompilerServices;
[assembly:InternalsVisibleTo("MyTests")]

关于c# - VS2017 .NET Standard 库中的单元测试内部方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42235401/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com