• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Test for a method containing a call to another method

 
Sahil Reddy
Ranch Hand
Posts: 145
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello

I have a method A() wherein i call method B() . I want to test whether method A() has a statement calling method B() or not. How can i achieve it in Junit 4 .

Thanks
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34073
335
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I can think of two options:

1) If method B does something, assert whether it happened
2) Create a dummy subclass of the class you are trying to test and have it override method b. Then you can set a variable in your subclass and know if b was called.
 
Gopi Chella
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just have a boolean getter and setter methods in your JUnit class, and from MethodB just pass "true" to setter method , so if Method A(Or any Method) called Method B then you will come to know through the value returning by the getter method.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic