How to verify in unit test that a method being tested is calling its super method (method in parent class)

116 Views Asked by At

Class A: Class being tested. Class A extends class B and overrides its method common().

i.e.

class B { 
  fun common() {}  
}

class A : B { 
 override fun common() { 
  if(x) { 
   doSomething() 
} else 
   super.common() }
}

Now if you are testing class A’s common() method, how will you verify that it is calling super.common() from within?

1

There are 1 best solutions below

6
Ralf Ulrich On

Unit tests are supposed to verify the effect of code. A very simple, generic and non-working, example is

code.setProperty(value);
assert(code.getProperty() == value);

Thus, I suppose your common does something in doSomething. This is what you test. If your common method would not do anything - it cannot be tested.

Your question is not complete in this aspect, so it cannot be answered more precisely at this moment.