-
Notifications
You must be signed in to change notification settings - Fork 253
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
PrivateObject and PrivateType are not available for a project targeting netcorapp2.0 #366
Comments
Just wanted to chime in that this would be a great addition to the testing framework. |
@shiitake Irony, I just came back to this question today to see if there had been any updates on it because I needed to use it again. I had not even checked my email yet to see the notification of a new comment |
`PrivateObject` class testing appears to be broken in .NET Core 2.0. See: * microsoft/testfx#366
Yes. Please. |
This is very useful and should be accessible in netcore. |
Oh, my god. Today I googling a lot, before I found this issue, that it is a known bug. But known bug for more than 8 months? Please add this functionality to .Net core tests also! |
any idea if this is ever going to happen? |
Any update on this? |
bump 👍 |
Agreed. This would be handy. I've been beating my head against a wall trying to figure out why I couldn't use this. |
It would be great to see some love for this. |
I'm unable to finish upgrading several existing .NET Framework projects to .NET Core 2.2 because their unit tests rely on UPDATE: |
DO IT PLEASE. NEED 😆 |
It is little things like this that make it hard for me to recommend moving some of our other .NET framework apps over to .net core... |
Please do this... |
It took a lot of time to get here. Please... 🙏 |
Any estimates on this? |
Personally I am glad that this hasn't been added to .NET Core / Standard. Testing of private stuff is an anti-pattern and should be avoided. However, if you absolutely cannot live without it (are doing migration of legacy stuff into .NET Core / Standard etc.), you could implement is yourself: |
You guys can copy the codes into your project at the moment. I'm personally using my own wrapper extension methods for PrivateObject and PrivateType, which depends on copied codes so that my NuGet package can be used on any environment (for MSTest V1/2 on .NET Framework and for MSTest/NUnit/xUnit on .NET Core). @skalinets IMO, these types are not mainly used for private invoke but for mocking. |
We discussed this internally and decided that we don't want to introduce this pattern back into the framework. In the attached zip file there is a single |
The following documentation has not been updated to state that PrivateObject and PrivateType is not available on .Net/Net Core projects:
Can this be updated to avoid future confusion for other devs reading Microsoft documentation? |
If this is not going to be available for the netcore, please update the documentation accordingly. |
I wrote a small extension method which enables you to call private methods 🎉 Have a look at the sample code: class Test
{
private string GetStr(string x, int y) => $"Success! {x} {y}";
}
var test = new Test();
var res = test.Invoke<string>("GetStr", "testparam", 123);
Console.WriteLine(res); // "Success! testparam 123" You can find the code here: https://gist.github.com/xpl0t/0d223222696a1c92d7d23cf8368800bf |
Description
Currently the classes located at
Microsoft.VisualStudio.QualityTools.UnitTestFramework.PrivateObject
andMicrosoft.VisualStudio.QualityTools.UnitTestFramework.PrivateType
are only available in the/src/TestFramework/Extension.Desktop/
project, this made sense in the past because the other project types did not support theSystem.Reflection
classes necessary to implement those two classes.However, as of netcoreapp2.0 those projects projects have access to all the needed classes in
System.Reflection
. A newExtension.CoreApp
project should be built, or the existingExtension.Desktop
project should be moved to the new VS15 style of projects so that<targetframeworks>netcoreapp2.0;net45</targetframeworks>
could be set.Steps to reproduce
PrivateObject
Expected behavior
PrivateObject is found and is useable
Actual behavior
PrivateObject is not available for projects referencing the assembly that was generated from Extensions.Core
The text was updated successfully, but these errors were encountered: