Projects记录

System.setOut in JUnit test didn

2018-09-29  本文已影响0人  greatseniorsde

Issue: The expected output is correctly displayed in console, but the JUnit actual value is "" which leads to assertion error and test failure.

Similar problem: https://stackoverflow.com/questions/46712632/systemoutrule-in-junit-test-didnt-capture-standard-output

After reading the solution on stackoverflow, I suspect it is caused by the version of JUnit. Then I took a closer look at another test java file that works to compare the one that doesn't work, and I found that it's true that I imported different version of JUnit in them, so I changed the imported file and then things worked fine.

//The commented ones don't work.
//import org.junit.*;
//import org.junit.jupiter.api.Test;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
上一篇下一篇

猜你喜欢

热点阅读