-
Notifications
You must be signed in to change notification settings - Fork 747
Parameterized method being called with no parameter #1872
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
Comments
It's because you've specified an empty TestCase in addition to creating tests using TestCaseSource. |
To expand/clarify what @appel1 is saying, the |
OK, thanks. I wish I had some free time, because the docs really need a lot of work. I will check back when my current side project is finished; maybe I'll have some more time then. |
@mbenningfield1 Hope you do have some time, but meanwhile could you point to where they are misleading regarding TestCase? |
Not misleading; perhaps more counter-intuitive; and with TestCaseSource, I realize that the docs mention that TestCaseSource additionally The name of TestCaseSource suggests -- grammatically speaking -- that is Now, this is not my first trip to town; I understand that there is no Once you know the paths, you no longer see the maze. Right now the docs Of course, that sort of thing is usually at the very bottom of the TODO On 10/30/2016 1:05 PM, CharliePoole wrote:
|
Well, the good news is that I've only seen this particular thing come up once before. 😄 However, I understand that it seems like a pretty natural thing to do. Maybe it's a bug that we allow you to use TestCase without an argument and then tell you it's wrong! |
As I understand it (granted, I'm a noob with NUnit), TestCase with no Any time you have 2 pieces of an API that do exactly the same thing, its or not needed, and pieces that aren't needed are "wigglies in the soup". I would say that if it's at all possible, amend the API to require args On 10/30/2016 10:09 PM, CharliePoole wrote:
|
It was never intended to be so, but the implementation allows it to be used that way. A few people have taken it that way, tried it out and found out that it works. That, of course, explains why it's not covered in the docs as much as anything else. |
Reopening this for discussion: Should we make it impossible to use TestCaseAttribute without args? |
As I quick test, I tried to add a private default constructor to TestCaseAttribute to hide the params constructor, but the params constructor still gets called. Therefore I don't think we can disable it at compile time. We could switch the null check in the params constructor to throw which would give a more meaningful error. It is still a runtime bug, but I would be okay with that since it is giving the user more information. That said, we also allow a [Test] with several TestCases or with a TestCaseSource. It doesn't cause side effects, but should it be an error? My feeling probably not. So, my vote is 👍 but I don't have strong feelings. |
In the past, I've used a constructor like `TestCase(object arg1, params object[] remaining) to force the inclusion of a first argument. It makes the constructor code a bit more complicated but doesn't impact the user. Extra [Test] and [TestFixture] attributes are a legacy thing that we allow for backward compatibility. It takes a small amount of special code for each of them - more for [TestFixture] because of inheritance. For example, we only generate a test for [Test] if it's the only attribute present on the method that generates tests. Just one annoying extra check. 😄 We could do the same for [TestCase] but I'm more inclined to make it not compile. |
That is a better idea for making it not compile, I didn't think of that. Base on that, I am more in favour of the idea 👍 |
Changed the labels but leaving it here in discussion for a beat. Anybody else have thoughts on this? |
For my part, I'm a firm believer in leaving client code as little room On 10/31/2016 6:41 PM, CharliePoole wrote:
|
Five days... anyone not commenting missed their chance. 😄 Adding to backlog. |
@rprouse My idea for making it not compile works... but doesn't. That is, it does prevent
So the error will have to be at run-time rather than compile-time. |
Runtime is less than ideal, but a better error message will be an improvement. |
-OR-
results in this:
It appears that an extra call to the parameterized method is being generated that uses no parameters.
The text was updated successfully, but these errors were encountered: