I'm trying to run junit on a "Standard" Hello World!
program. Here's my program:
public class HelloWorld{
public static void main (String[] argv)
{
System.out.println("Hello World!");
}
}
What I want to do is call this file and run assertEquals("Hello, World!", output);
on it. I've tried a few different things with no success. The first was installing System-Rules by adding it to a lib folder, then importingimport static org.junit.contrib.java.lang.system.TextFromStandardInputStream.*;
In this script:
import static org.junit.Assert.*;
import org.junit.Test;
import static org.junit.contrib.java.lang.system.TextFromStandardInputStream.*;
public void HelloWorldTest {
@Rule
public final SystemOutRule systemOutRule = new SystemOutRule().enableLog();
@Test
public void writesTextToSystemOut() {
assertEquals("hello world", systemOutRule.getLog());
}
}
This script threw a bunch of errors and ultimately failed. The other thing I tried was extending class Hello World, but that didn't work either. My ultimate goal here is to be able to run a test on the file HelloWorld.java
with no modification to the HelloWorld.java file.
I much appreciate the help!
Aucun commentaire:
Enregistrer un commentaire