JetBrains Rider 2022.2 Help

Code Inspection: NUnit. Incompatible argument type or incorrect argument value

This inspection notifies you about mismatch of the type of a value that you pass to your test via the TestCase argument and the type of the corresponding parameter in the test method. For example, in the test method below the error is quite obvious:

[TestCase("one")] public void Test9(int x) { // do something }

But sometimes, the error can be harder to spot. For example

[TestCase(1, 2)] public void Test4(int[] values) { // do something }

In this case, the array will not be created automatically, so the argument must be an array for the test to work correctly:

[TestCase(new [] {1, 2})] public void Test4(int[] values) { // do something }

Note that NUnit will try to convert the value supplied via ExpectedResult before using it in the test, and JetBrains Rider takes this conversion into consideration before issuing the warning. Note also, that NUnit 2.x and NUnit 3 have different value conversion logic.

Last modified: 08 March 2021