简体   繁体   中英

Junit testing void method

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM