-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add test case for stefanbirkner/system-rules#8.
- Loading branch information
1 parent
ea54965
commit bcf1fcb
Showing
3 changed files
with
100 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
<?xml version="1.0"?> | ||
<project name="java-junit-template-project" default="test" basedir="."> | ||
<!-- build all classes in this directory --> | ||
|
||
<property name="main.build.dir" value="build/main" /> | ||
<property name="main.src.dir" value="src" /> | ||
<property name="test.build.dir" value="build/test" /> | ||
<property name="test.src.dir" value="test" /> | ||
|
||
<path id="classpath.base" /> | ||
|
||
<path id="classpath.test"> | ||
<pathelement location="lib/junit-4.11.jar" /> | ||
<pathelement location="lib/hamcrest-core-1.3.jar" /> | ||
<pathelement location="lib/system-rules-1.3.1.jar" /> | ||
<pathelement location="${main.build.dir}"/> | ||
<path refid="classpath.base" /> | ||
</path> | ||
|
||
<target name="test" depends="run, clean" /> | ||
|
||
<target name="compile"> | ||
<mkdir dir="${main.build.dir}"/> | ||
<javac srcdir="${main.src.dir}" destdir="${main.build.dir}" includeantruntime="false"> | ||
<classpath refid="classpath.base"/> | ||
</javac> | ||
</target> | ||
|
||
<target name="build" depends="compile"> | ||
<mkdir dir="${test.build.dir}"/> | ||
<javac srcdir="${test.src.dir}" destdir="${test.build.dir}" includeantruntime="false"> | ||
<classpath refid="classpath.test"/> | ||
</javac> | ||
<echo message="Build done" /> | ||
</target> | ||
|
||
<!-- Test and build all files --> | ||
<!-- To run this: use "ant" (default) or "ant run" --> | ||
<target name="run" depends="build"> | ||
<junit printsummary="on" haltonfailure="yes" failureProperty="test.failure"> | ||
<classpath> | ||
<path refid="classpath.test" /> | ||
<pathelement location="${test.build.dir}"/> | ||
</classpath> | ||
<formatter type="brief" usefile="false" /> | ||
<batchtest> | ||
<fileset dir="${test.src.dir}" includes="**/*Test*.java" /> | ||
</batchtest> | ||
</junit> | ||
<fail message="test failed" if="test.failure" /> | ||
</target> | ||
|
||
<!-- delete all class files --> | ||
<!-- To run this: use "ant clean" --> | ||
<target name="clean"> | ||
<delete> | ||
<fileset dir="${basedir}" includes="**/*.class" /> | ||
</delete> | ||
<echo message="clean done" /> | ||
</target> | ||
</project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package uk.co.placona.helloWorld; | ||
|
||
public class HelloWorld { | ||
|
||
public String sayHello() { | ||
return "Hello World"; | ||
} | ||
|
||
public void printHello() { | ||
System.out.print(sayHello()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package helloWorld; | ||
|
||
import static org.junit.Assert.*; | ||
|
||
import org.junit.*; | ||
import org.junit.contrib.java.lang.system.StandardOutputStreamLog; | ||
import uk.co.placona.helloWorld.HelloWorld; | ||
|
||
|
||
public class HelloWorldTest { | ||
|
||
@Rule | ||
public final StandardOutputStreamLog log = new StandardOutputStreamLog(); | ||
|
||
@Test | ||
public void testHellowWorld(){ | ||
HelloWorld hello = new HelloWorld(); | ||
assertEquals("A test for Hello World String", "Hello World", hello.sayHello()); | ||
} | ||
|
||
@Test | ||
public void printsHelloWorld() { | ||
HelloWorld hello = new HelloWorld(); | ||
hello.printHello(); | ||
assertEquals("Wrong output", "Hello World", log.getLog()); | ||
} | ||
} |