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

IF statement in MySQL trigger -

c++ - What does MSC in "// appease MSC" comments mean? -

javascript - Blogger related post gadget image Resize s72-c [ Need Expert Help ] -