-
-
Notifications
You must be signed in to change notification settings - Fork 96
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
An observation / question about using testTheory with 'null' and '"" as inputs #493
Comments
Thanks for the examples! It sounds like the problem is that null and empty string are, by default, rendered as the same string so the test name for both cases is the same and the test runner gets mad, thus displaying only one test. I'd guess the solution here is to introduce a pretty printer that detects special values like this. That'd probably be changed here let inline testTheory name cases test =
let caseToTest case =
testCase (string case) <| fun () ->
// ^^^^^^^ Just conjecture though. I haven't tried anything yet |
Just from a quick go with Expectos own tests, it does look like a different string function like let inline private stringify (value : 'T) =
if typeof<'T> = typeof<string> then
if value = Unchecked.defaultof<'T> then "null" else value.ToString()
else
string value
/// Builds a theory test case
let inline testTheory name cases test =
let caseToTest case =
testCase (stringify case) <| fun () ->
test case |> ignore
testList name (cases |> Seq.map caseToTest |> List.ofSeq) lets these cases pass testTheory "odd numbers" [1; 3; 5] <| fun x ->
Expect.isTrue (x % 2 = 1) "should be odd"
testTheory "empty strings" [""; null] <| fun x ->
Expect.isTrue (System.String.IsNullOrEmpty(x)) "should be null or empty" |
Moving this from the PR for discoverability and potential continued discussion
|
An observation whilst trying to do a few simple error case input tests with
testTheory
-I noticed that if I have test code like
The the test explorer in Ionide only showed one test:
And then when I tried running from the command line, I got
Maybe it's not a typical thing to do in F#, but for comparison If I do the same thing in NUnit with TestCase then it puts the string 'null' in the test name rather than an empty string so that the two tests show up differently:
![image](https://private-user-images.githubusercontent.com/1178570/313467820-4d45e908-0fc9-4df4-a98a-47a18b412f8e.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjEyNTkyNTEsIm5iZiI6MTcyMTI1ODk1MSwicGF0aCI6Ii8xMTc4NTcwLzMxMzQ2NzgyMC00ZDQ1ZTkwOC0wZmM5LTRkZjQtYTk4YS00N2ExOGI0MTJmOGUucG5nP1gtQW16LUFsZ29yaXRobT1BV1M0LUhNQUMtU0hBMjU2JlgtQW16LUNyZWRlbnRpYWw9QUtJQVZDT0RZTFNBNTNQUUs0WkElMkYyMDI0MDcxNyUyRnVzLWVhc3QtMSUyRnMzJTJGYXdzNF9yZXF1ZXN0JlgtQW16LURhdGU9MjAyNDA3MTdUMjMyOTExWiZYLUFtei1FeHBpcmVzPTMwMCZYLUFtei1TaWduYXR1cmU9ZmI0YTk0MGYwYTYyZThjZGU3OTk5ZmMxOTg0ZjQ5NTFhNDdhMzJjZWMxMDczM2VhNTkxZjlkYWRhMTZmY2MxNiZYLUFtei1TaWduZWRIZWFkZXJzPWhvc3QmYWN0b3JfaWQ9MCZrZXlfaWQ9MCZyZXBvX2lkPTAifQ.wFD8E_fADEr5tvyCo-wd_VifURZsyun50W1lP9k0uVs)
So maybe it'd be possible to do something similar here?
Thanks
The text was updated successfully, but these errors were encountered: