The type or namespace name 'PrivateObject' could not be found
I am using Visual Studio 2017 and I was trying to create a unit test of a private method in C# (code below):
[TestClass]
public class CalculatorTests
{
[TestMethod]
public void TestCalculator_Hello()
{
var calc = new Calculator(1);
var privateObject = new PrivateObject(calc);
string expected = "hello!";
string result = privateObject.Invoke("HelloTest");
Assert.AreEqual(expected, result);
}
}
However, I got this error message:
Error CS0246 The type or namespace name 'PrivateObject' could not be found
I've looked up for articles and tutorials but I still don't know what I am doing wrong.
c# unit-testing
add a comment |
I am using Visual Studio 2017 and I was trying to create a unit test of a private method in C# (code below):
[TestClass]
public class CalculatorTests
{
[TestMethod]
public void TestCalculator_Hello()
{
var calc = new Calculator(1);
var privateObject = new PrivateObject(calc);
string expected = "hello!";
string result = privateObject.Invoke("HelloTest");
Assert.AreEqual(expected, result);
}
}
However, I got this error message:
Error CS0246 The type or namespace name 'PrivateObject' could not be found
I've looked up for articles and tutorials but I still don't know what I am doing wrong.
c# unit-testing
1
You may be missing a reference to its assemblyMicrosoft.VisualStudio.TestPlatform.TestFramework.Extensions.dll
docs.microsoft.com/en-us/dotnet/api/…
– Nkosi
Nov 13 '18 at 3:14
add a comment |
I am using Visual Studio 2017 and I was trying to create a unit test of a private method in C# (code below):
[TestClass]
public class CalculatorTests
{
[TestMethod]
public void TestCalculator_Hello()
{
var calc = new Calculator(1);
var privateObject = new PrivateObject(calc);
string expected = "hello!";
string result = privateObject.Invoke("HelloTest");
Assert.AreEqual(expected, result);
}
}
However, I got this error message:
Error CS0246 The type or namespace name 'PrivateObject' could not be found
I've looked up for articles and tutorials but I still don't know what I am doing wrong.
c# unit-testing
I am using Visual Studio 2017 and I was trying to create a unit test of a private method in C# (code below):
[TestClass]
public class CalculatorTests
{
[TestMethod]
public void TestCalculator_Hello()
{
var calc = new Calculator(1);
var privateObject = new PrivateObject(calc);
string expected = "hello!";
string result = privateObject.Invoke("HelloTest");
Assert.AreEqual(expected, result);
}
}
However, I got this error message:
Error CS0246 The type or namespace name 'PrivateObject' could not be found
I've looked up for articles and tutorials but I still don't know what I am doing wrong.
c# unit-testing
c# unit-testing
asked Nov 13 '18 at 3:11
PauloPaulo
141
141
1
You may be missing a reference to its assemblyMicrosoft.VisualStudio.TestPlatform.TestFramework.Extensions.dll
docs.microsoft.com/en-us/dotnet/api/…
– Nkosi
Nov 13 '18 at 3:14
add a comment |
1
You may be missing a reference to its assemblyMicrosoft.VisualStudio.TestPlatform.TestFramework.Extensions.dll
docs.microsoft.com/en-us/dotnet/api/…
– Nkosi
Nov 13 '18 at 3:14
1
1
You may be missing a reference to its assembly
Microsoft.VisualStudio.TestPlatform.TestFramework.Extensions.dll
docs.microsoft.com/en-us/dotnet/api/…– Nkosi
Nov 13 '18 at 3:14
You may be missing a reference to its assembly
Microsoft.VisualStudio.TestPlatform.TestFramework.Extensions.dll
docs.microsoft.com/en-us/dotnet/api/…– Nkosi
Nov 13 '18 at 3:14
add a comment |
2 Answers
2
active
oldest
votes
While PrivateObject
shares the same Microsoft.VisualStudio.TestTools.UnitTesting
namespace as TestMethodAttribute
and related attribues, it belong to a separate assembly
Microsoft.VisualStudio.TestPlatform.TestFramework.Extensions.dll
Check to make sure that the assembly is referenced by the test project.
You also need to cast the result because Invoke
returns an object
string result = (string)privateObject.Invoke("HelloTest");
add a comment |
if you hover over PrivateObject( and right click.. is there an option for go to definition?
that command will tell you what it thinks that class is..
if you cannot go to definition via the context menu, then it means you're missing a reference and the compiler doesn't know what PrivateObject is..
If that is the case, you can add a reference to it via your NuGet Package Manager or by right clicking the project and going to Add Reference.
Also remember to add the Namespace to the top of the file with a using statement, once those are all in place it should know what that object is.
You should not get any errors at that point, and your Go to Definition context menu should take you to an actual class definition.
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53273228%2fthe-type-or-namespace-name-privateobject-could-not-be-found%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
While PrivateObject
shares the same Microsoft.VisualStudio.TestTools.UnitTesting
namespace as TestMethodAttribute
and related attribues, it belong to a separate assembly
Microsoft.VisualStudio.TestPlatform.TestFramework.Extensions.dll
Check to make sure that the assembly is referenced by the test project.
You also need to cast the result because Invoke
returns an object
string result = (string)privateObject.Invoke("HelloTest");
add a comment |
While PrivateObject
shares the same Microsoft.VisualStudio.TestTools.UnitTesting
namespace as TestMethodAttribute
and related attribues, it belong to a separate assembly
Microsoft.VisualStudio.TestPlatform.TestFramework.Extensions.dll
Check to make sure that the assembly is referenced by the test project.
You also need to cast the result because Invoke
returns an object
string result = (string)privateObject.Invoke("HelloTest");
add a comment |
While PrivateObject
shares the same Microsoft.VisualStudio.TestTools.UnitTesting
namespace as TestMethodAttribute
and related attribues, it belong to a separate assembly
Microsoft.VisualStudio.TestPlatform.TestFramework.Extensions.dll
Check to make sure that the assembly is referenced by the test project.
You also need to cast the result because Invoke
returns an object
string result = (string)privateObject.Invoke("HelloTest");
While PrivateObject
shares the same Microsoft.VisualStudio.TestTools.UnitTesting
namespace as TestMethodAttribute
and related attribues, it belong to a separate assembly
Microsoft.VisualStudio.TestPlatform.TestFramework.Extensions.dll
Check to make sure that the assembly is referenced by the test project.
You also need to cast the result because Invoke
returns an object
string result = (string)privateObject.Invoke("HelloTest");
answered Nov 13 '18 at 3:22
NkosiNkosi
111k16123190
111k16123190
add a comment |
add a comment |
if you hover over PrivateObject( and right click.. is there an option for go to definition?
that command will tell you what it thinks that class is..
if you cannot go to definition via the context menu, then it means you're missing a reference and the compiler doesn't know what PrivateObject is..
If that is the case, you can add a reference to it via your NuGet Package Manager or by right clicking the project and going to Add Reference.
Also remember to add the Namespace to the top of the file with a using statement, once those are all in place it should know what that object is.
You should not get any errors at that point, and your Go to Definition context menu should take you to an actual class definition.
add a comment |
if you hover over PrivateObject( and right click.. is there an option for go to definition?
that command will tell you what it thinks that class is..
if you cannot go to definition via the context menu, then it means you're missing a reference and the compiler doesn't know what PrivateObject is..
If that is the case, you can add a reference to it via your NuGet Package Manager or by right clicking the project and going to Add Reference.
Also remember to add the Namespace to the top of the file with a using statement, once those are all in place it should know what that object is.
You should not get any errors at that point, and your Go to Definition context menu should take you to an actual class definition.
add a comment |
if you hover over PrivateObject( and right click.. is there an option for go to definition?
that command will tell you what it thinks that class is..
if you cannot go to definition via the context menu, then it means you're missing a reference and the compiler doesn't know what PrivateObject is..
If that is the case, you can add a reference to it via your NuGet Package Manager or by right clicking the project and going to Add Reference.
Also remember to add the Namespace to the top of the file with a using statement, once those are all in place it should know what that object is.
You should not get any errors at that point, and your Go to Definition context menu should take you to an actual class definition.
if you hover over PrivateObject( and right click.. is there an option for go to definition?
that command will tell you what it thinks that class is..
if you cannot go to definition via the context menu, then it means you're missing a reference and the compiler doesn't know what PrivateObject is..
If that is the case, you can add a reference to it via your NuGet Package Manager or by right clicking the project and going to Add Reference.
Also remember to add the Namespace to the top of the file with a using statement, once those are all in place it should know what that object is.
You should not get any errors at that point, and your Go to Definition context menu should take you to an actual class definition.
answered Nov 13 '18 at 3:26
JBoothUAJBoothUA
845424
845424
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53273228%2fthe-type-or-namespace-name-privateobject-could-not-be-found%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
You may be missing a reference to its assembly
Microsoft.VisualStudio.TestPlatform.TestFramework.Extensions.dll
docs.microsoft.com/en-us/dotnet/api/…– Nkosi
Nov 13 '18 at 3:14