junit - How to test print that made by function? -


i have function should print string. want test through junit function printing supposed print. how it?

for example, function:

public static void test(int a){     system.out.println(a + "^2=" + (a*a)); } 

and want check = 3 printing 3^2=9

ps, can not change function.

why don't try this.hope work you.

public void testprint {     @rule     public final standardoutputstreamlog log = new standardoutputstreamlog();      @test     public static void test(int a) {         system.out.print(a + "^2=" + (a*a));         assertequals("3^2=9", log.getlog());     } } 

Comments

Popular posts from this blog

android - How to save instance state of selected radiobutton on menu -

python 3 IndexError: list index out of range -

IF statement in MySQL trigger -