java - Mock final new instance created? -


how mock private final mockclass mockclass = new mockclass();

 public class simpleclass {      private final mockclass mockclass = new mockclass();  } 

use dependency injection; can have whatever want in field:

class simpleclass {   private final mockclass mockclass;    simpleclass(mockclass mockclass) {     this.mockclass = mockclass;   } } 

see misko hevery's guide writing testable code: code example of warning sign "new keyword in constructor or @ field declaration".


Comments

Popular posts from this blog

Lists in Python -

android - can not access to progress bar in an other activity -

html - Not able to access next element of an array javascript -