VS2017 .Net标准库中的单元测试内部方法

编程入门 行业动态 更新时间:2024-10-24 20:11:45
本文介绍了VS2017 .Net标准库中的单元测试内部方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

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

I am currently playing around with the latest Visual Studio 2017 Release Candidate by creating a .Net Standard 1.6 library. I am using xUnit to unit test my code and was wondering if you can still testing internal methods in VS2017.

我记得您可以在中全部使用AssemblyInfo.cs类VS2015,它将使指定的项目能够查看内部方法

I remember that you could all a line AssemblyInfo.cs class in VS2015 that would enable specified projects to see internal methods

[assembly:InternalsVisibleTo("MyTests")]

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

As there is no AssemblyInfo.cs class in VS2017 .Net Standard projects I was wondering if you can still unit test internal methods?

推荐答案

根据 .NET文档 InternalsVisibleToAttribute :

该属性在程序集级别应用。这意味着它可以包含在源代码文件的开头,也可以包含在Visual Studio项目的AssemblyInfo文件中。

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文件中,并且应该可以正常工作:

In other words, you can simply place it in your own arbitrarily named .cs file, and it should work fine:

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

更多推荐

VS2017 .Net标准库中的单元测试内部方法

本文发布于:2023-11-13 23:56:57,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1585647.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:库中   单元测试   标准   方法   Net

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!