Skip to content
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

Add support for .NET Core testing #3

Closed
jcansdale opened this issue Jun 30, 2016 · 9 comments
Closed

Add support for .NET Core testing #3

jcansdale opened this issue Jun 30, 2016 · 9 comments
Assignees
Milestone

Comments

@jcansdale
Copy link
Owner

.NET Core CLI test communication protocol
https://docs.microsoft.com/en-us/dotnet/articles/core/tools/test-protocol

@plioi
Copy link

plioi commented Jun 30, 2016

It's possible that the dotnet test client/server handshake described in that link would allow TestDriven.NET to sidestep things like the lack of AppDomains in .NET Core, by playing the role of the IDE. A test framework's own dotnet test implementation would then run instead of a TestDriven-specific plugin per test framework.

@plioi
Copy link

plioi commented Jun 30, 2016

It may be easier to see what the handshake would be like by seeing xUnit's side: https://github.com/xunit/dotnet-test-xunit
https://github.com/xunit/dotnet-test-xunit/blob/master/src/dotnet-test-xunit/CommandLine.cs#L223

It's a handful of JSON messages going back and forth.

@jcansdale
Copy link
Owner Author

You're right, it's handy there is a standard wire protocol for dotnet core testing. Hopefully there is a standard naming convention for tests as well. I look forward to getting this working. :)

@jcansdale
Copy link
Owner Author

jcansdale commented Jun 30, 2016

Looks like the 'Microsoft.Extensions.Testing.Abstraction' package on NuGet could be useful as well. Crazy number of dependencies though!

Also, the NUnit runner for .NET Core:
https://github.com/nunit/dotnet-test-nunit
https://github.com/nunit/dotnet-test-nunit/blob/master/src/dotnet-test-nunit/CommandLineOptions.cs#L233

@jcansdale
Copy link
Owner Author

Current version of TestDriven.Net can't see assembly for .xproj projects.

I believe the following should work:

        static string findBuiltFile(Project project)
        {
            var outputGroup = project.ConfigurationManager.ActiveConfiguration.OutputGroups.Item("Built");
            var urls = (object[])outputGroup.FileURLs;
            foreach (var url in urls)
            {
                return new Uri((string)url).LocalPath;
            }

            return null;
        }

@jcansdale
Copy link
Owner Author

I'm wondering what the best way to detect a .NET Core assembly from for a classic .NET application. I can load the .NET Core assembly fine and reflect on it.

If an assembly references "System.Runtime", is that a clear indication that it's a .NET Core assembly? Is "System.Runtime" the .NET Core equivalent of mscorlib?

@jcansdale
Copy link
Owner Author

https://twitter.com/bradwilson/status/749613448565104640
"No. System.Runtime started with PCLs."
@bradwilson

I'll maybe look for the following instead:
[assembly: TargetFramework(".NETCoreApp,Version=v1.0")]

@jcansdale
Copy link
Owner Author

jcansdale commented Jul 6, 2016

Picking up from conversation with @bradwilson at #4.

Given that you're doing that, you should look at the special hooks already required by the Visual Studio test runner, and see if you can reuse them.

I'm planning to initially make it compatible with this interface. I've done some experiments and it looks like the following should work (same with class and namespace):

dotnet test -designtime -method myclass.mymethod

There are definitely optimizations that would make it faster (Microsoft.Extensions.Testing.Abstractions seems to have a crazy number of dependencies).

I'm surprised. I expected you to ask people to code to your existing API, just with a .NET Core compatible API surface.

This is pretty much what I've done with the ad-hoc runner. It would certainly make sense to clean this up and allow people to implement as an alternative to the VS interface (say with a -tdnet switch). This would make tests run faster because there's no need to use the symbol reader or pull in so many dependencies! I might make it a single source file that could be compiled as part of 'dotnet.test.xunit'.

@jcansdale jcansdale self-assigned this Jul 7, 2016
@jcansdale jcansdale added this to the v4 milestone Jul 7, 2016
@jcansdale
Copy link
Owner Author

jcansdale commented Jul 7, 2016

TestDriven.NET-4.0.0_Extraterrestrial_Alpha.zip

I have finally got support for running ad-hoc test methods working with .NET Core. It doesn't know about xUnit or NUnit tests yet, but this is a good start.

Please give the attached (above) installer a try and let me know how you get on! Simply target any .NET Core method (or property) and 'Run Test(s)'. 'Test With > Debugger' doesn't work yet. You can also return an object and it will dump its properties and fields. 🚀

@jcansdale jcansdale modified the milestones: v4.0a, v4 Jul 20, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants