fsprojects / fsharp-language-server

Other
219 stars 37 forks source link

Run & Debug tests: Xunit possible? #46

Closed hoetz closed 5 years ago

hoetz commented 5 years ago

What would it take to get xunit tests decorated with [Fact] et al. to work with the debug test command?

hoetz commented 5 years ago

Ok, adding "Fact" here is a first step and on my local dev version the tests already show up. dotnet test starts but it's waiting for the debugger to attach but it never does 🤔

https://github.com/fsprojects/fsharp-language-server/blob/cff4c38fa7172c1f458aeac603d7c29ad90f15d1/src/FSharpLanguageServer/Program.fs#L127

image

georgewfraser commented 5 years ago

The "Debug Test" code lens issues a custom notification that invokes this function:

https://github.com/fsprojects/fsharp-language-server/blob/cff4c38fa7172c1f458aeac603d7c29ad90f15d1/client/extension.ts#L83

So it's basically just a question of making that function support xunit.

georgewfraser commented 5 years ago

Also, the debugger starts paused for some complicated reason that I forget. So you may just need to press play...it would be nice if that were not necessary, obviously.

hoetz commented 5 years ago

Indeed, pressing "play" worked :) The pull request I submitted provides support for Fact / Theory tests and is certified "works on my machine"

hoetz commented 5 years ago

For future reference, this is how omnisharp implements test detection https://github.com/OmniSharp/omnisharp-roslyn/tree/6836fadb9c35a88d4695276d14302336a460b841/src/OmniSharp.DotNetTest/TestFrameworks

georgewfraser commented 5 years ago

The problem with that approach is you have to parse and typecheck the code, and typechecking takes time, especially in F#. Code lenses need to be computed fast, so we have to figure out how to find the test methods by just parsing the code.