-
Notifications
You must be signed in to change notification settings - Fork 34
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
Tests with custom [Test]
attibute gives NUnit1027 when tests have arguments
#494
Comments
Thanks for raising this @lucasteles , as well as for already getting the fscheck perspective by asking there too. While this issue tracker is a good place for framework-related or general issues, in this case it sounds like we suspect any nunit-side fix could be in the analyzer and so the best place for a discussion and any potential fix would be here: https://github.com/nunit/nunit.analyzers/issues I'm unable to move it over myself; @mikkelbu do you have the right permissions? |
The nunit.analyzer rule for NUnit1027 detects certain extensions: Looking at FsCheckProperty it does implement ISimpleTestBuilder. This is before my time, so I don't know if FsCheckProperty should implement |
@lucasteles I've transferred the issue to the nunit.analyzers repository. Can you give an example of this problem - just for more context as I don't know much about FsCheck? Preferably a small project that I can experiment with. I've only skimmed the FsCheckProperty code, but if it implements ISimpleTestBuilder, then it sounds odd that it also has parameters as ISimpleTestBuilder is "...used by attributes that know how to build a single, non-parameterized test from a MethodInfo..." to quote the documentation that @manfred-brands linked to above (emphasis mine). Also looking at the FsCheckPropertyAttribute source code it seems like it implements its own testrunner that don't follow the usual conventions in NUnit. Perhaps if PropertyAttribute derived from ITestBuilder instead of ISimpleTestBuilder then I think the problem would go away (but then they should also derive from another attribute - although I'm not sure they need to do it). I need to experiment some with FsCheckProperty as I have never used it, but my initial feeling is that it would be odd to special case this in the analyzers given that they don't follow the conventions as far as I can tell - the also state
But perhaps my experiments will make me change my mind. EDIT: Also how to you execute the tests? I would think that NUnits own testrunners would be confused about the ISimpleTestBuilder vs method having parameters. |
Sorry to be late to the game here. A property is somewhat subtly different from a parametrized test, although it does look very similar of course (i.e. as a function with a bunch of parameters.) I believe the reason FsCheckProperty implements ISimpleTestBuilder and not ITestBuilder is that the number of test cases for a single property is open-ended. If a randomly generated test case fails, for example, then FsCheck starts a process knowns as "shrinking": the failing values are used as a seed and incrementally made smaller (i.e. collections are made shorter, integers smaller etc) until the test stops failing. This produces a minimal failing test case that is typically easier to debug. In other words, from the ITestBuilder docs:
FsCheck cannot do this before actually running the test. All that said, feel free to point us in the direction of a more appropriate NUnit extension point than |
Using the normal NUnit runner. It does not appear to cause any confusion. |
Finally, for your consideration: the xunit analyzer had the same problem with FsCheck's property, and fixed it by not triggering on attributes that are subtypes of the in-box xunit FactAttribute & friends: Can I suggest a similar approach here? |
Sorry about overlooking the last comments - I guess I lost track of them in a busy period. I've taken a closer look at FsCheck, the NUnit ITestBuilder vs ISimpleTestBuilder, and also the xunit issue. As I see there are at least two paths going forward:
I can live with both approaches - @manfred-brands Do you have any opinions on this? |
By default I would go for pt.1 above, only trigger on our own attributes. If possible allow an option (using a rule for this perhaps) for also triggering on subtypes. |
@mikkelbu Even though FsCheck seems to use the interfaces contrary the original intensions, they have a working system. As the system is more flexible, we can only test what we know and that is our There is a small risk we will no longer pick up tests with other custom attributes, but we don't know if these add an implicit parameter to tests or not. So I vote also for option 1, but also add a configuration option: Should we then also adjust the checks for the |
NUnit have an analyser package to help on common mistakes
One of them is when you expect arguments in an
[Test]
, it gives the NUnit1027 error. It predicts that only[TestCase]
can have parameters.So I'm using FsCheck which has our
PropertyAttribute
which inherits fromTestAttribute
. This attribute accuses error on the analyzer because it passes arguments to test (fscheck/FsCheck#623)Workarounds:
NUnit1027
checkIt would be good to have a way to make the analyzer ignore some kinds of custom test attributes
The text was updated successfully, but these errors were encountered: