Classes not recognized in their unit test code
-
2012년 5월 1일 화요일 오후 7:19I have a C# class library, which I'll call "MyLibrary," for which I have made a unit test project, which I will call "MyLibrary.Test." MyLibrary contains several class definitions. Currently, all of these references are broken. Specifically, they are marked with the error "The type or namespace name 'MyClass' could not be found (are you missing a using directive or an assembly reference?)." Both the using directive and the assembly reference are present, like so:
using System;
using System.Collections.Generic;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using MyLibrary;
namespace MyLibrary.Test
{
/// <summary>
/// Test class for MyLibrary.MyClass.
/// </summary>
[TestClass()]
public class MyClassTest
{
private TestContext testContextInstance;
public TestContext TestContext [...]
internal virtual MyClass CreateMyClass()
{
[...]
}
What is the problem and how do I resolve it?
모든 응답
-
2012년 5월 1일 화요일 오후 7:48
From this snippet is not possible to understand which is the problem.
Does MyClass exist?
Matteo Migliore
Bloghttp://blogs.ugidotnet.org/matteomigliore
Twitterhttp://twitter.com/matteomigliore
CodePlex- 편집됨 Matteo Migliore 2012년 5월 1일 화요일 오후 7:49
-
2012년 5월 2일 수요일 오전 2:26Yes, MyClass exists.
-
2012년 5월 2일 수요일 오전 2:53
Try to open the project folder in Explorer, delete the "obj" and "bin" folders and rebuild the solution.Matteo Migliore
Bloghttp://blogs.ugidotnet.org/matteomigliore
Twitterhttp://twitter.com/matteomigliore
CodePlex- 답변으로 표시됨 Jay Bienvenu (Stuller, Inc.) 2012년 5월 2일 수요일 오후 7:48
-
2012년 5월 2일 수요일 오전 4:57
I have to ask,
Have you added a reference to the DLL containing MyClass in your unit test project?
(right click on the project -> click on Add Reference -> select the project/DLL containing the class)
Regards,
Alvaro -
2012년 5월 2일 수요일 오전 7:15
Hello,
Do these classes marked as internal ? if they do you should either change them to public or use the InternalVisibleToAttribute.
Eyal (http://shilony.net), Regards.
-
2012년 5월 2일 수요일 오전 9:17중재자
Please expand the projects reference in your Visual Studio, and then open your this problem source code page in your Visual Studio.
Now, take a screenshot and share it to us in your post.
Before the problem occurred, what have you did to your this Visual Studio solution?
Commonly, we will try to delete the references form the project, and the re-add them, if we face the reference problem.
If there's any concern, please feel free to let me know.
Best wishes,
Mike Zhang[MSFT]
MSDN Community Support | Feedback to us

