java - Testing console output -


got question regarding testing console output.

stdoutput class:

public abstract class stdouttest {      private final printstream stdoutmock = mock(printstream.class);     private final printstream stdoutorig = system.out;      @before     public void setup() {         system.setout(this.stdoutmock);     }      @after     public void teardown() {         system.setout(this.stdoutorig);     }      protected final printstream getstdoutmock() {         return this.stdoutmock;     } } 

now here don't understand:

public class test extends stdouttest{      @before     public void setup(){         //empty     }      @test     public void example(){         system.out.println("hello");         verify(getstdoutmock()).println("hello");     } } 

i use mockito verify , test passes when delete setup(), setup() fails. fail message says:

hello   wanted not invoked: printstream.println("hello"); -> @ observer_test.test.example(test.java:18) actually, there 0 interactions mock. 

can me perhaps on why happens?

your subclass overriding setup method of superclass empty method. can fix adding call superclass method:

@before public void setup(){     super.setup(); } 

or can delete setup method in subclass if don't need perform custom setup in there.


Comments

Popular posts from this blog

mysql - Dreamhost PyCharm Django Python 3 Launching a Site -

java - Sending SMS with SMSLib and Web Services -

java - How to resolve The method toString() in the type Object is not applicable for the arguments (InputStream) -