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
Post a Comment