haf / expecto

A smooth testing lib for F#. APIs made for humans! Strong testing methodologies for everyone!
Apache License 2.0
663 stars 96 forks source link

Most test types are discoverable by test explorer, but `testTask` type is not #445

Closed drk-mtr closed 1 year ago

drk-mtr commented 1 year ago

When using the test explorer in VS code, tests that use the test or testAsync approach are picked up fine as expected, but tests of type testTask are not.

image

This could well be user error or unsupported functionality in the VS Code test explorer, rather than an Expecto issue specifically, because in Visual Studio I can see testTask tests (even if their names are built programmatically, which is rather impressive).

Repro

  1. Create new project using dotnet new expecto.
  2. Open project in VS code.
  3. Run dotnet build.
  4. Add a test of type testTask to the samples test list.

Expected: All tests including testTask are discovered i.e. can be run via UI. Actual: testTake cannot be run, others can.

Notes

Issue also present in Visual Studio.

Versions:

Workaround

This works but is not ideal:

testAsync "this is a task test" {
    return! task {
        let! n = Task.FromResult 2
        Expect.equal n 2 "n=2"
    } |> Async.AwaitTask
}

Thanks for the brilliant library!

ratsclub commented 1 year ago

Thanks for reporting it, @drk-mtr! Could you provide a repository with the code that is producing this, please?

baronfel commented 1 year ago

@drk-mtr are you using a test explorer extension, or are you relying on Ionide's built-in test detection? Ionide's version is built on source code analysis only, and so any changes to pick up testTask would need to happy by adding to the list of known identifiers here

ratsclub commented 1 year ago

@baronfel Oh, I didn't know about that, I guess the fix is really simple then!

baronfel commented 1 year ago

@ratsclub want to try sending a PR over with the change?

ratsclub commented 1 year ago

@baronfel I opened the PR there.

ratsclub commented 1 year ago

@drk-mtr The fix should be included in FsAutoComplete's next release.

drk-mtr commented 1 year ago

Brilliant, thank you!

Numpsy commented 10 months ago

Hi, I'm not sure if this is an issue here, or in Ionide or FSAutoComplete, but - I seem to have a similar situation with testTheory - The test explorer pane is listing the tests from the testTheory, but the editor window has no markers for the test, and right click -> run tests at cursor seems to either run everything in the test list, or just the previous test case in the file

image

I thought this was maybe the same situation as the op, where FsAutoComplete needs to be taught to recognize 'testTheory' but then I see that Ionide has recently had a rework to how test discovery works, so I'm not sure where the responsibility lies.

Thanks

farlee2121 commented 10 months ago

@Numpsy testTheory items show in the explorer due to the new changes that base the explorer on test results. The code locations of tests are still found exclusively through code analysis. A code location is necessary for the gutter decorations you noticed as missing.

In short, this is the same issue as before. This method in the code analyzer needs to be looking for testTheory.

Numpsy commented 10 months ago

Ok, thanks. I can see about doing a PR for it, if no one else gets to it before I manage to build FsAutoComplete (never tried before)

baronfel commented 10 months ago

@Numpsy yes, we'd love any and all enhancements to the test discovery in FSAC!

Numpsy commented 9 months ago

Ok, my tests are getting highlighted now ith Ionide 7.11:

image