简体   繁体   中英

F# XUnit Test Not Discovered

The console runner is unable to discover the tests in my F# project. Code for the project can be found here:

https://github.com/valainisgt/FsXunitExample

Here is the command I'm running (from the repo's root):

packages\xunit.runner.console.2.3.1\tools\net452\xunit.console.exe Library1\bin\Debug\Library1.dll

And here are the results:

xUnit.net Console Runner (64-bit Desktop .NET 4.0.30319.42000)
  Discovering: Library1
  Discovered:  Library1
=== TEST EXECUTION SUMMARY ===
   Library1.dll  Total: 0

What's going on here?

Your test is a value , not a function . Values get initialized once, at program start (roughly speaking). Functions, on the other hand, are executed every time they are called.

Xunit requires tests to be functions (in .NET terminology, "methods"), so that it can execute them after discovery.

In F#, functions differ from values by the presence of parameters: if you have parameters, you're a function; otherwise, you're a value. To make your test a function, just give it a unit parameter:

[<Fact>]
let trueIsTrue () =
    let actual = returnsTrue ()
    Assert.True(actual)

Such function will be represented in IL as a parameterless static method, which is what Xunit recognizes as a test.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM