I have problem with that and i dont know how to fix it.
This is my class:
import java.util.Scanner;
public class ScannerAndKeyboard
{
public static void main(String[] args)
{ Scanner s = new Scanner(System.in);
System.out.print( "Enter your name: " );
String name = s.nextLine();
System.out.println( "Hello " + name + "!" );
}
}
and this is my test junit
public class ScannerAndKeyboardTest {
@Rule
public final TextFromStandardInputStream systemInMock = emptyStandardInputStream();
@Rule
public final SystemOutRule OutLog = new SystemOutRule().enableLog();
@Test
public void Name() {
String name = "Name";
String expectedConsoleOutput = "Enter your name: Hello Name!" + System.lineSeparator();
systemInMock.provideLines(name);
ScannerAndKeyboardTest.main(new String[] {});
Assert.assertEquals(expectedConsoleOutput,OutLog.getLog());
}
private static void main(String[] strings) {
}
}
here is line number 31
Assert.assertEquals(expectedConsoleOutput,OutLog.getLog());
Can someone tell me what im doing wrong and why this log is empty? I making my first steps in this
Aucun commentaire:
Enregistrer un commentaire