0

Started to write tests for our old project. Everything is simple - [TestClass], [TestMethod] etc.
But there's some method - we call it Create for example - and it have 4 nullable parameters - Create(int? a, int? b, Guid? c, int? d). There's no way to rewrite the method, and while I can enclose main call into delegate - Action or Func - anyway I must call near 16 variants of function in case of testing all situations, where params can be some one predefined value or can be null:

Test(null,null,null,null); 
Test(1,null,null,null); 
Test(1,1,null,null);
Test(null,1,null,null);
//etc

But why if there's not only 1 and null, but even 2?Robot Bender saw 2
I can try to write something, which will receive sets and produce calls, but maybe there's a ready-to-use solution without third-party components?

Troll the Legacy
  • 675
  • 2
  • 7
  • 22
  • [How to run a test method with multiple parameters in MSTest?](https://stackoverflow.com/questions/9021881/how-to-run-a-test-method-with-multiple-parameters-in-mstest/13710788#13710788) – stuartd Apr 05 '19 at 13:43
  • Your image is not shown. – FranzHuber23 Apr 05 '19 at 13:45
  • Still need to write all 16 sets. That's wrong. – Troll the Legacy Apr 05 '19 at 13:46
  • Just to clearify: You have a method with 4 optional parameters and want to test it. What exactly is the problem with this? – FranzHuber23 Apr 05 '19 at 13:46
  • @TrolltheLegacy What is `bender.jpg`? It's not shown in the post. – FranzHuber23 Apr 05 '19 at 13:47
  • @TrolltheLegacy What exactly is wrong about writing the 16+ test cases? Basically, if the method demands those 4 inputs, you'll have to write the tests. If you'd like to test thoroughly, it could be even more, depending on your requirements. – Paul Kertscher Apr 05 '19 at 13:52
  • 16 variants today, 81 variants tomorrow. Why I must write them all manually? Isn't something like `TestCallCrossParams({null,1},{null,1},{null,someTestGuid},{null,1})` simplier? – Troll the Legacy Apr 05 '19 at 13:55
  • @FranzHuber23 it's about Friday – Troll the Legacy Apr 05 '19 at 13:56
  • Well as @PaulKertscher said , if your method signature demands it , you must do it.However you can take a look at [TestCaseSource](https://nunit.org/docs/2.6/testCaseSource.html) – Bercovici Adrian Apr 05 '19 at 14:03
  • Now I understand the problem. I agree with PaulKertscher and Bercovici Adrian. Either check the project Adrian mentioned or write all of the tests. – FranzHuber23 Apr 05 '19 at 14:09
  • If you are doing glass-box (aka white-box) testing, you may not need to test all combinations. From the knowledge about the internals of the code you may conclude that testing certain combinations does not bring improvements. For example, if the function has an entry test where, if the first parameter is null, an exception is thrown, there is little value in testing the first parameter as null with all the combinations of the other parameters. – Dirk Herrmann Apr 16 '19 at 22:47

0 Answers0