简体   繁体   English

Visual Studio是否将测试类编译为程序集?

[英]Does Visual Studio compile test classes into an assembly?

Does Visual Studio compile classes marked with test attributes into an assembly? Visual Studio是否将标有测试属性的类编译为程序集? Suppose this assembly has internal classes that could benefit from unit test coverage. 假设此程序集具有一些内部类,这些类可以从单元测试的覆盖范围中受益。

Assuming you've got a separate test project, yes that's really just another class library project. 假设您有一个单独的测试项目,是的,这实际上只是另一个类库项目。 (If you're expecting VS to split classes from a single project into "test" and "non-test" assemblies, then the answer is no... and you shouldn't do that :) (如果您期望VS将类从单个项目拆分为“测试”和“非测试”程序集,那么答案是否定的……您不应该这样做:)

Unit testing internal classes is entirely reasonable - and is by far the most important reason for InternalsVisibleToAttribute . 对内部类进行单元测试是完全合理的-到目前为止,这是InternalsVisibleToAttribute的最重要原因。 You make your production internal classes visible to your test project, and then you can test them. 使生产内部类对测试项目可见,然后可以对其进行测试。

Yes. 是。 More specifically, Visual Studio takes the classes contained within a test project and generates a DLL via the compilation process. 更具体地说,Visual Studio接受测试项目中包含的类,并通过编译过程生成DLL。

If you create a separate test project, it will get compiled into a different assembly from the main project. 如果创建一个单独的测试项目,它将被编译为与主项目不同的程序集。 Often, the test project just gets ignored when you deploy so the client will never see it. 通常,部署时测试项目只会被忽略,因此客户端将永远看不到它。 One good way to wrap your mind around it is to try: 尝试解决问题的一种好方法是尝试:

> vstest.console MyTestProject\bin\Debug\MyTestProject.dll

The test runner only picks up the test assembly. 测试运行程序仅拾取测试组件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在 Visual Studio 中编译时获取程序集名称 - Get Assembly name at compile time in Visual Studio 为什么 visual studio 将所有新类标记为<compile Remove />在我的 csproj 文件中? - Why does visual studio mark all new classes as <Compile Remove /> in my csproj file? Visual Studio不会将程序集复制到GAC中 - visual studio does not copy assembly into gac 成功的 Visual Studio C# 构建不会创建程序集 - Successful Visual Studio C# build does not create assembly Visual Studio 2019 配置编译的 .dll 程序集不存在 - Visual Studio 2019 configuration the complied .dll assembly does not exist Visual Studio解决方案无法编译,但项目确实如此 - Visual Studio solution doesn't compile, but project does Windows Phone的Visual Studio 2012:字体Segoe WP无法编译 - Visual Studio 2012 for Windows Phone: Font Segoe WP does not compile 我的Visual Studio C#编译需要多长时间? - How long does my Visual Studio C# compile take? Visual Studio 2017 RC Core Console项目无法编译 - Visual Studio 2017 RC Core Console Project does not compile MSIL-我可以找到用于构建/编译.NET程序集的Visual Studio版本吗? - MSIL - Can I find the Visual Studio version that was used to build/compile a .NET assembly?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM