dotnet --info output: 1.0.0-preview2-003133
VS Code version: 1.9.0-insider
C# Extension version: 1.6.2
For us the problem was nested classes. OmniSharp cannot handle this, when we click run test.
public class SomeClass
{
public class SomeMethod
{
// Trying to run this test causes
// "Failed to run test because null"
[Fact]
public void SomeTest()
{
}
}
}
The test runs and the output says "Test Passed".
Failed to run test because null
Thanks. This looks like a dupe of #1100
@gregg-miskelly It is not necessarily a dupe (depending on how we define dupe), because there are multiple reasons why Omnisharp might give that error. See also: http://stackoverflow.com/q/40858172/1108891
Okay, I will reopen for now then.
Yeah, this has a different error. However, the "dupe" is from several months ago, so it might just be that behavior has changed since then. I suspect we started hitting null with this change: https://github.com/OmniSharp/omnisharp-roslyn/pull/683
FWIW, this will require a fix in omnisharp-roslyn. Looking at the code in https://github.com/OmniSharp/omnisharp-roslyn/blob/master/src/OmniSharp.DotNetTest/Helpers/TestFeaturesDiscover.cs, I can see how it might fail to locate tests in nested classes. I'll take a look at this shortly.
shortly == tomorrow. :smile:
Note: There's also #743
Looks like the problem is that there's some hacky code in omnisharp-roslyn that searches specifically for the presence of 'project.json'. https://github.com/OmniSharp/omnisharp-roslyn/blob/dev/src/OmniSharp.DotNetTest/Helpers/ProjectPathResolver.cs#L11
OK. I see why the problem is specific to tests in nested classes. The offending line of code is here: https://github.com/OmniSharp/omnisharp-roslyn/blob/dev/src/OmniSharp.DotNetTest/Helpers/TestFeaturesDiscover.cs#L41.
Essentially, the code expects Roslyn's ISymbol.ToDisplayName() to return a name that can be used with 'dotnet test'. However, that method returns strings for _display_. Between a class and a nested class, it uses a '.' separator. However, 'dotnet test' expects a metadata name when the class and nested class are separated by a '+'. I had to write code that produced a metadata name once before -- for Code Model in VS (https://github.com/dotnet/roslyn/blob/master/src/VisualStudio/Core/Impl/CodeModel/MetadataNameHelpers.cs). Looks like I might have to do that again. :smile:
OK. I've got a fix for this in omnisharp-roslyn.