-2

I have an object called buscaminas with some methods.

@BeforeEach
Buscaminas buscaminas = new Buscaminas();
    
@Test
void createMines(){
    buscaminas.createMines(3);
}

How can I check that the method is working well, generating 3 mines using JUnit tools?

Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197
  • 3
    If the mines property is private, add a getMines() method, otherwise you will need to [use reflection to get the property value](http://tutorials.jenkov.com/java-reflection/private-fields-and-methods.html). – Paul Samsotha Dec 03 '20 at 18:42
  • Does this answer your question? [JUNIT testing void methods](https://stackoverflow.com/questions/16043819/junit-testing-void-methods) – Robert Dec 03 '20 at 21:08
  • What does this method do? Does it update some propery in `buscaminas`? do you have a getter for it? – Mureinik Dec 05 '20 at 09:27

1 Answers1

0

The whole idea of JUnit is to promote "Test-Driven Design/Development", but read that closely. If you are writing a test, and need some piece of information to be successful in the testing, then your design should accommodate it. In your case, your testing is revealing that the createMines method should return int, not void. Change it, and your testing effort becomes trivial. And.... now you are adhering to TDD.

Jeff Bennett
  • 996
  • 7
  • 18