0

Hi I have a class which the invoke the run() method of a thread from the constructor of the class by calling the start() method , So please help me to Stubs the so to write the junit test cases . The class is as follows

public class MyClass extends Thread { Student st=null; University uni= new University();

 public MyClass(Student st)    {
     this.st=st;
     start();
 }
 public void run()     {
    uni.calculate(st);
 }
  }

Thanks

Biplab Mitra
  • 327
  • 2
  • 5
  • 12

1 Answers1

0

Take a look at the discussion here:

Testing Constructor With Powermock

It discusses sub-classing and overriding.

In general it should be considered bad practice to have to mock the class under test in order to test it. It is also hard to do since most mocking frameworks will not allow mocking a single method once in the class under test since they create wrapping proxies.

Community
  • 1
  • 1
John B
  • 32,493
  • 6
  • 77
  • 98