question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Parameterized tests with TestCaseSource attribute not working

See original GitHub issue

Description

I want to run parameterized test using the NUnit attribute TestCaseSource. Please tell me how to do that and add code examples for paremterized tests to the documentation on https://fsprojects.github.io/FsUnit/NUnit.html.

Repro steps

Run the code snippet

namespace FooSpace

module FooTests =
    
    open NUnit.Framework
    open FsUnit

    let mySrc1 = [|
            (17, "One", 1.5);
            (42, "Two", 2.3);
        |]

    let mySrc2 = [|
            [| (17, "One", 1.5) |];
            [| (42, "Two", 2.3) |];
        |]

    let mySrc3 = seq {
            yield (17, "One", 1.5)
            yield (42, "Two", 2.3)
        }

    [<Test>]
    [<TestCaseSource("mySrc1")>]
    let testFoo (testData: int * string * float) =
        let foo, bar, umu = testData
        1 |> should equal 1

Note that I tried different flavours of test case sources above, based on (rather old) search results from the web like, e.g.

Expected behavior

A dotnet test discovers two test cases, both are run and succeed.

Actual behavior

Two test cases are discovered and run, but both fail with the error message

Not enough arguments provided, provide at least 3 arguments.
  Exception doesn't have a stacktrace

no matter if one uses mySrc1, mySrc2 or mySrc3.

Known workarounds

None.

Related information

  • Windows 8.1
  • FsUnit Release 3.8.0
  • .NET Core 3.1

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:9 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
svdHerocommented, Feb 12, 2020

Okay. Well. Thanks for your help anyway. I’m closing this issue.

1reaction
svdHerocommented, Feb 12, 2020

Ah, sorry. My fault. I only now saw the member keyword. I got it. The class is necessary. Let me try…

Read more comments on GitHub >

github_iconTop Results From Across the Web

c# - nunit-console does not run tests parameterized with ...
Trying to run Nunit tests parameterized with TestCase attribute. Something like this: [TestFixture] public class MyClass { [Test] ...
Read more >
NUnit Tutorial: Parameterized Tests With Examples
In this guide, we will showcase NUnit parameterized test cases along with the commonly used attributes like the TestFixture NUnit attribute.
Read more >
TestCaseSource
TestCaseSource. TestCaseSourceAttribute is used on a parameterized test method to identify the source from which the required arguments will be provided.
Read more >
NUnit Tests Using "TestCaseSource" Not Correctly ...
NUnit has an attribute that allows a test to get parameterized data from a source method - the TestCaseSourceAttribute.
Read more >
How to write Nunit Parameterized Test
In this technique, Nunit uses the TestCase attribute to pass the various data sets at Test level. This technique is helpful when we...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found