Jannat Arora
Jannat Arora

Reputation: 2989

JUnit test case for methods returning void

I have a method whose signature is:

void method1(int i,int j);

Now I wish to create a JUnit test case for this method, but I am not sure as to how I should make it. I am a novice at Java, so please excuse me.

I know I need to use assertEquals() but I am not sure as to how I should use it.

Can someone please help me?

Upvotes: 1

Views: 2075

Answers (2)

Makoto
Makoto

Reputation: 106389

A method that is void would indicate that something about the state of the object has changed. You can tailor your unit test to verify what you expected to change did.

It would also be beneficial to include getters as necessary, to make retrieving state information about your object easier.

Upvotes: 0

Frank
Frank

Reputation: 15631

The fact that the method return void, is usually not a problem. You need to think on how this method changes the state of your object and how you can retrieve this change in state.

Maybe you class has some getter method and you can call your assert on this one. Sometimes it can even be the toString() of you class that you need to Assert.

If you post some code i can adapt my answer to be more concrete.

Upvotes: 5

Related Questions