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.

NUnit question/ request?

See original GitHub issue

I am experimenting with FsCheck using C# and NUnit as shown below in the code. I wonder why properties MUST be declared with a verbose syntax as in method ‘ThisWorks’ while the much simpler version ‘ThisShouldAlsoWorkButItWontCompile’ gives a compilation related to the FsCheck Property attribute error saying: “The test method has ‘2’ parameter(s), but only ‘0’ argument(s) are supplied by attributes.”

It should be possible to transform the latter function into the first one automatically by FsCheck. It would result in much more readable/maintainable/portable tests. Why not?

public class NUnitTests
{
    private int Add(int x, int y) // Method under test
    {
        return x + y;
    }

    [Property(Verbose = false, MaxTest = 200)]
    public Property ThisWorks()
    {
      Func<int,int,bool> summer = (a,b) => Add(a,b) == a + b;
      return Prop.ForAll(summer);
    }
    
    [Property(Verbose = false, MaxTest = 200)]
    public bool ThisShouldAlsoWorkButItWontCompile(int x, int y)
    {
        return Add(x,y) == x+y;
    }
}

Issue Analytics

  • State:closed
  • Created 2 months ago
  • Comments:14 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
kurtschelfthoutcommented, Jul 20, 2023

FsCheck’s Property is only superficially similar to TestCase. It is not possible to do what you suggest.

The NUnit analyser is clearly too eager here. Turn it off and/or check in with the NUnit people so they can fix it.

0reactions
kurtschelfthoutcommented, Jul 23, 2023

Closing as dupe

Read more comments on GitHub >

github_iconTop Results From Across the Web

Top 20 NUnit Interview Questions and Answers 2023
This article is focused on frequently asked NUnit Interview Questions that cover NUnit's Core features, Attributes, installation, and many more.
Read more >
How do I Test Controller HTTP Methods with Nunit test?
This is an integration test because you're actually making HTTP requests. The advantage is you are also testing the actual service ...
Read more >
Top 40 NUnit Interview Questions: To Crack Your Next ...
Prepare to ace your NUnit interviews questions with our thorough set of solutions that ... Here are some NUnit assertion method examples:.
Read more >
How to mock the Request.form for only a few values on ...
I am new to Nunit and Moq framework and am totally stuck in testing for one of my controller as it fetches some...
Read more >
NUnit With C#
NUnit is a unit-testing framework for .NET applications in which the entire application is isolated into diverse modules.
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