0

I create a board with items and these items are created randomly for a game which is some kind of a match-3 game. There are some cases that I want to test. Can you suggest any methodology to test cases that are produced randomly?

Best

Simulant
  • 19,190
  • 8
  • 63
  • 98
small_ticket
  • 1,910
  • 5
  • 22
  • 30
  • Not without a lot more information. – Thom Oct 24 '12 at 11:25
  • I'm not really sure what kind of info I should provide but let me give an example of what i want. I need to produce new items such that, there should be a possible 5-match move occurs on the board. Is that clear or what else should i tell you? – small_ticket Oct 24 '12 at 11:35

2 Answers2

2

Using TestNG, you can use 'Parametrized' tests, and seed them via any data provider: http://www.mkyong.com/unittest/testng-tutorial-6-parameterized-test/, e.g. a simple csv file.

You might want to start with an extensive list of possible inputs, and afterwards find a set of inputs that gives you the highest coverage of your class under test.

Test coverage tools can check if each possible execution path of your code was reached during the test with the given inputs.

Maybe that's not enough, but to reverse engineer the possible inputs that gives a certain output is more of a task for artificial intelligence engines.

GeertPt
  • 16,398
  • 2
  • 37
  • 61
0

For test Scenarios containing random(e.g. Numbers), you need a RandomGenerator, where you can set the Seed. If the Seed is the same, the generated Numbers will always be the same, in the same order. For the test you set the Seed to a fixed value, for the real application you will use a variable value like System.getMilliSeconds(). So you can check the correctness of your test result for one Seed, after that you can repeat your tests as often as you want, if the results changes, but your Seed not you found an Error-Case.

Simulant
  • 19,190
  • 8
  • 63
  • 98
  • thanks for the reply. The seed will provide me to produce the same input, but I need specific inputs. e.g I need to produce new items such that, there should be a possible 5-match move occurs in the board. It is more than generating same input but generating the same case. Am I clear? – small_ticket Oct 24 '12 at 11:33
  • Yes, out of the same Seed you will always generate the same sequense of "random" numbers. So you get always the same case to evaluate. – Simulant Oct 24 '12 at 11:39
  • So what you are suggesting is as far as i understand something like this. Give a seed and see the generated items, based on these items generate your board and this will make your case valid. Change the seed or the board for every different case. Am i right? – small_ticket Oct 24 '12 at 11:49
  • Yes, if you need several test cases, save for every case the seed, so the test is repeatable and produces the same results. – Simulant Oct 24 '12 at 12:03