I have a junit test that requires a user to confirm a prerequisite state and as such the user is prompted before the test proceeds. This is for an integration test involving an external system that cannot be mocked. This works fine when running the test through the Eclipse IDE, but not through Gradle.
I understand that this is because Gradle sets an empty standard input. This can be resolved for the run target as per this question: Console application with Java and gradle. However, I have not been able to find an equivalent solution for the test target.
Is there a way to receive user input for a junit test run through Gradle?
A simplified version of the test class I'm using is given below:
@Test
public void testDigitalRead()
{
Scanner in = new Scanner(System.in);
out.println("Press enter to continue.");
in.nextLine();
// perform testing logic
in.close();
}
The above code will throw a java.util.NoSuchElementException when run through Gradle since there is no input to read.