How we can write system.assert statement for the method returning void.
Honestly, you make assertions for a method that returns
void the same way you write assertions for anything else you're testing. Assertions are about validating the results of running a piece of code.
- If your method is inserting a record, assert that you have one more record after running the code compared to before (query before and after)
- If your method is updating a record, assert that the value of the field(s) you're updating were actually changed (again, query the record(s) before and after running your code)
- If your method returns a value, assert that the return value is what you expect it to be
- If your method modifies a class's public state (i.e. changes a value in a public class variable), assert that that change happened and that the new value is what you expect
If the method you're testing does more than one of those things, then write assertions to verify all of the different output (though better practice would probably be to break that up into separate test methods).
My list above isn't exhaustive, but it should do fine as an example. Again, the key to success here is that you're making assertions to verify that that thing(s) you think your code should be doing are actually being done (and done correctly).