import org.junit.contrib.java.lang.system.SystemOutRule;
import org.junit.contrib.java.lang.system.TextFromStandardInputStream;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import com.pholser.junit.quickcheck.Property;
import com.pholser.junit.quickcheck.runner.JUnitQuickcheck;
@RunWith(JUnitQuickcheck.class)
public class MyClassTest {
@Rule
public final SystemOutRule systemOutRule = new SystemOutRule().enableLog();
@Rule
public final TextFromStandardInputStream systemInMock = TextFromStandardInputStream.emptyStandardInputStream();
@Property
public void myMethodTest(int input) {
systemInMock.provideLines(Integer.toString(input));
MyClass.myMethod();
assertThat(systemOutRule.getLog(), containsString("Expected Output"));
// ...
}
}
<dependency>
<groupId>com.pholser</groupId>
<artifactId>junit-quickcheck-core</artifactId>
<version>0.8</version>
<scope>test</scope>
</dependency>
gradle
testImplementation 'com.pholser:junit-quickcheck-core:0.8'