How to write a junit testcase for a void method that creates a new object

后端 未结 2 1754
北海茫月
北海茫月 2021-01-28 15:35
public class SupportController{

    public void disableUserAccount(String username) throws Exception {
        UserAccount userAccount = 
                new UserAccoun         


        
2条回答
  •  傲寒
    傲寒 (楼主)
    2021-01-28 16:23

    I would suggest using Mock Objects.

    Besides that, you can check the JUnit FAQ, where you can find a section about testing methods that return void.

    Often if a method doesn't return a value, it will have some side effect. Actually, if it doesn't return a value AND doesn't have a side effect, it isn't doing anything.

    There may be a way to verify that the side effect actually occurred as expected

提交回复
热议问题