简体   繁体   English

单元测试项目参考控制台应用程序VS2015

[英]Unit Test Project References Console Application VS2015

I am aware that there are many questions already answered about this but nothing works for me. 我知道有关此问题已经回答了很多问题,但对我来说却无济于事。

I have a Console Application that I need to be unit tested. 我有一个控制台应用程序,需要进行单元测试。 I have the Unit Test project in the same solution, both of them target the same platform, I added the reference from The Unit test project to the Console App and a few other things that I don't remember at the moment since I've been stuck for two days on this one. 我在同一解决方案中有单元测试项目,它们都针对相同的平台,我将单元测试项目的引用添加到了控制台应用程序中,还有一些我现在不记得的其他事情。被困了两天。 Yet, the Unit Tests don't recognize the namespace of the referenced project. 但是,单元测试无法识别所引用项目的名称空间。

在此处输入图片说明

It says "The type or namespace name CLASSNAME does not exist in the namespace NAMESPACE", when it clearly does. 它明确指出“类型或名称空间名称CLASSNAME在名称空间NAMESPACE中不存在”。

Can anyone tell me what might be the issue, since I've checked all the obvious ones and it still doesn't want to work? 既然我已经检查了所有明显的问题,但仍然不想工作,谁能告诉我这是什么问题?

The class that you want to initialize at the UnitTest project from the main project must be public. 您要在主项目的UnitTest项目上初始化的类必须是公共的。 By default the c# classes are internal. 默认情况下,c#类是内部的。 So first check if the desired class that you want to unit test is a public class. 因此,首先检查您要进行单元测试的所需类是否为公共类。 Then add the needed using statement and everything should work. 然后添加所需的using语句,一切都会正常进行。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM