Skip to content

Commit 6b64a6d

Browse files
committed
simple junit
junit example
1 parent 4a4a17c commit 6b64a6d

9 files changed

Lines changed: 213 additions & 0 deletions

File tree

simple-junit/.classpath

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<classpath>
3+
<classpathentry kind="src" path="src/test/java" output="target/test-classes" including="**/*.java"/>
4+
<classpathentry kind="src" path="src/main/java" including="**/*.java"/>
5+
<classpathentry kind="output" path="target/classes"/>
6+
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
7+
<classpathentry kind="var" path="M2_REPO/junit/junit/4.11/junit-4.11.jar"/>
8+
<classpathentry kind="var" path="M2_REPO/org/hamcrest/hamcrest-core/1.3/hamcrest-core-1.3.jar"/>
9+
</classpath>

simple-junit/.project

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<projectDescription>
3+
<name>simple-junit</name>
4+
<comment>NO_M2ECLIPSE_SUPPORT: Project files created with the maven-eclipse-plugin are not supported in M2Eclipse.</comment>
5+
<projects/>
6+
<buildSpec>
7+
<buildCommand>
8+
<name>org.eclipse.jdt.core.javabuilder</name>
9+
</buildCommand>
10+
</buildSpec>
11+
<natures>
12+
<nature>org.eclipse.jdt.core.javanature</nature>
13+
</natures>
14+
</projectDescription>

simple-junit/pom.xml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
3+
<modelVersion>4.0.0</modelVersion>
4+
5+
<groupId>com.hmkcode</groupId>
6+
<artifactId>simple-junit</artifactId>
7+
<version>1.0-SNAPSHOT</version>
8+
<packaging>jar</packaging>
9+
10+
<name>simple-junit</name>
11+
<url>http://maven.apache.org</url>
12+
13+
<properties>
14+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
15+
</properties>
16+
17+
<dependencies>
18+
<dependency>
19+
<groupId>junit</groupId>
20+
<artifactId>junit</artifactId>
21+
<version>4.11</version>
22+
<scope>test</scope>
23+
</dependency>
24+
</dependencies>
25+
</project>
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package com.hmkcode.junit;
2+
3+
/**
4+
* Hello world!
5+
*
6+
*/
7+
public class Math
8+
{
9+
public static void main( String[] args )
10+
{
11+
System.out.println( "Hello World!" );
12+
}
13+
14+
public double sum(double x, double y){
15+
return x+y;
16+
}
17+
public double multiply(double x, double y){
18+
return x*y;
19+
}
20+
public double divide(double x, double y){
21+
return x/y;
22+
}
23+
public double subtract(double x, double y){
24+
return x - y;
25+
}
26+
27+
28+
29+
}
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
package com.hmkcode.junit;
2+
3+
import static org.junit.Assert.assertThat;
4+
5+
import org.junit.Rule;
6+
import org.junit.Test;
7+
import org.junit.Ignore;
8+
import org.junit.rules.Timeout;
9+
import org.junit.runner.RunWith;
10+
import org.junit.runners.JUnit4;
11+
import static org.hamcrest.CoreMatchers.not;
12+
import static org.hamcrest.CoreMatchers.is;
13+
14+
15+
/**
16+
* Tests for {@link Math}.
17+
*
18+
* @author hmkcode@gmail.com (Hani HMK)
19+
*/
20+
@RunWith(JUnit4.class)
21+
public class MathTest {
22+
23+
@Rule
24+
public Timeout globalTimeout = new Timeout(3000); // 3 seconds max per method tested
25+
26+
27+
com.hmkcode.junit.Math math = new com.hmkcode.junit.Math();
28+
29+
30+
@Test
31+
@Ignore
32+
public void testAssertNotNull() {
33+
org.junit.Assert.assertNotNull("should not be null", math);
34+
}
35+
36+
@Test
37+
public void testSum(){
38+
org.junit.Assert.assertTrue("failure - not equal", math.sum(3, 2) == 5);
39+
40+
//to test timeout
41+
/*for (;;) {
42+
}*/
43+
}
44+
45+
@Test
46+
public void testMultiply(){
47+
org.junit.Assert.assertTrue("failure - not equal", math.multiply(3, 2) == 6);
48+
}
49+
50+
@Test
51+
public void testDivide(){
52+
double x = 3,y = 2;
53+
assertThat("failure - can't divide by 0",y, is(not(0.0)));
54+
org.junit.Assert.assertTrue("failure - not equal", math.divide(x, y) == 1.5);
55+
}
56+
57+
@Test
58+
public void testSubtract(){
59+
org.junit.Assert.assertTrue("failure - not equal", math.subtract(3, 2) == 1);
60+
}
61+
62+
63+
}
929 Bytes
Binary file not shown.
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
<?xml version="1.0" encoding="UTF-8" ?>
2+
<testsuite failures="0" time="0.059" errors="0" skipped="1" tests="5" name="com.hmkcode.junit.MathTest">
3+
<properties>
4+
<property name="java.runtime.name" value="Java(TM) SE Runtime Environment"/>
5+
<property name="sun.boot.library.path" value="C:\Program Files\Java\jdk1.6.0_26\jre\bin"/>
6+
<property name="java.vm.version" value="20.1-b02"/>
7+
<property name="java.vm.vendor" value="Sun Microsystems Inc."/>
8+
<property name="java.vendor.url" value="http://java.sun.com/"/>
9+
<property name="path.separator" value=";"/>
10+
<property name="guice.disable.misplaced.annotation.check" value="true"/>
11+
<property name="java.vm.name" value="Java HotSpot(TM) 64-Bit Server VM"/>
12+
<property name="file.encoding.pkg" value="sun.io"/>
13+
<property name="user.country" value="US"/>
14+
<property name="sun.java.launcher" value="SUN_STANDARD"/>
15+
<property name="sun.os.patch.level" value="Service Pack 1"/>
16+
<property name="java.vm.specification.name" value="Java Virtual Machine Specification"/>
17+
<property name="user.dir" value="C:\Workspace\Maven_Projects\simple-junit"/>
18+
<property name="java.runtime.version" value="1.6.0_26-b03"/>
19+
<property name="java.awt.graphicsenv" value="sun.awt.Win32GraphicsEnvironment"/>
20+
<property name="java.endorsed.dirs" value="C:\Program Files\Java\jdk1.6.0_26\jre\lib\endorsed"/>
21+
<property name="os.arch" value="amd64"/>
22+
<property name="java.io.tmpdir" value="C:\Users\HMK\AppData\Local\Temp\"/>
23+
<property name="line.separator" value="
24+
"/>
25+
<property name="java.vm.specification.vendor" value="Sun Microsystems Inc."/>
26+
<property name="user.variant" value=""/>
27+
<property name="os.name" value="Windows 7"/>
28+
<property name="classworlds.conf" value="C:\Workspace\apache-maven-3.0.4\bin\..\bin\m2.conf"/>
29+
<property name="sun.jnu.encoding" value="Cp1256"/>
30+
<property name="java.library.path" value="C:\Program Files\Java\jdk1.6.0_26\bin;C:\Windows\Sun\Java\bin;C:\Windows\system32;C:\Windows;C:\Ruby193\bin;C:\Ruby200-x64\bin;C:\Program Files\Common Files\Microsoft Shared\Windows Live;C:\Program Files (x86)\Common Files\Microsoft Shared\Windows Live;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\Windows Live\Shared;C:\Program Files (x86)\ATI Technologies\ATI.ACE\Core-Static;C:\Program Files\WIDCOMM\Bluetooth Software\;C:\Program Files\WIDCOMM\Bluetooth Software\syswow64;C:\Program Files\Intel\WiFi\bin\;C:\Program Files\Common Files\Intel\WirelessCommon\;C:\Program Files (x86)\QuickTime\QTSystem\;C:\Program Files (x86)\Microsoft ASP.NET\ASP.NET Web Pages\v1.0\;C:\Workspace\apache-maven-3.0.4\bin;C:\Workspace\adt\sdk\platform-tools;C:\Workspace\adt\sdk\tools;C:\Workspace\apache-ant-1.8.4\bin;C:\Workspace\nodejs\;C:\Program Files (x86)\Java\jdk1.7.0\bin;C:\Users\HMK\AppData\Roaming\npm;;."/>
31+
<property name="java.specification.name" value="Java Platform API Specification"/>
32+
<property name="java.class.version" value="50.0"/>
33+
<property name="sun.management.compiler" value="HotSpot 64-Bit Tiered Compilers"/>
34+
<property name="os.version" value="6.1"/>
35+
<property name="user.home" value="C:\Users\HMK"/>
36+
<property name="user.timezone" value="Asia/Riyadh"/>
37+
<property name="java.awt.printerjob" value="sun.awt.windows.WPrinterJob"/>
38+
<property name="file.encoding" value="Cp1252"/>
39+
<property name="java.specification.version" value="1.6"/>
40+
<property name="user.name" value="HMK"/>
41+
<property name="java.class.path" value="C:\Workspace\apache-maven-3.0.4\bin\..\boot\plexus-classworlds-2.4.jar"/>
42+
<property name="java.vm.specification.version" value="1.0"/>
43+
<property name="sun.arch.data.model" value="64"/>
44+
<property name="java.home" value="C:\Program Files\Java\jdk1.6.0_26\jre"/>
45+
<property name="sun.java.command" value="org.codehaus.plexus.classworlds.launcher.Launcher test"/>
46+
<property name="java.specification.vendor" value="Sun Microsystems Inc."/>
47+
<property name="user.language" value="en"/>
48+
<property name="awt.toolkit" value="sun.awt.windows.WToolkit"/>
49+
<property name="java.vm.info" value="mixed mode"/>
50+
<property name="java.version" value="1.6.0_26"/>
51+
<property name="java.ext.dirs" value="C:\Program Files\Java\jdk1.6.0_26\jre\lib\ext;C:\Windows\Sun\Java\lib\ext"/>
52+
<property name="sun.boot.class.path" value="C:\Program Files\Java\jdk1.6.0_26\jre\lib\resources.jar;C:\Program Files\Java\jdk1.6.0_26\jre\lib\rt.jar;C:\Program Files\Java\jdk1.6.0_26\jre\lib\sunrsasign.jar;C:\Program Files\Java\jdk1.6.0_26\jre\lib\jsse.jar;C:\Program Files\Java\jdk1.6.0_26\jre\lib\jce.jar;C:\Program Files\Java\jdk1.6.0_26\jre\lib\charsets.jar;C:\Program Files\Java\jdk1.6.0_26\jre\lib\modules\jdk.boot.jar;C:\Program Files\Java\jdk1.6.0_26\jre\classes"/>
53+
<property name="java.vendor" value="Sun Microsystems Inc."/>
54+
<property name="maven.home" value="C:\Workspace\apache-maven-3.0.4\bin\.."/>
55+
<property name="file.separator" value="\"/>
56+
<property name="java.vendor.url.bug" value="http://java.sun.com/cgi-bin/bugreport.cgi"/>
57+
<property name="sun.cpu.endian" value="little"/>
58+
<property name="sun.io.unicode.encoding" value="UnicodeLittle"/>
59+
<property name="sun.desktop" value="windows"/>
60+
<property name="sun.cpu.isalist" value="amd64"/>
61+
</properties>
62+
<testcase time="0" classname="com.hmkcode.junit.MathTest" name="testAssertNotNull">
63+
<skipped/>
64+
</testcase>
65+
<testcase time="0" classname="com.hmkcode.junit.MathTest" name="testSum"/>
66+
<testcase time="0" classname="com.hmkcode.junit.MathTest" name="testSubtract"/>
67+
<testcase time="0" classname="com.hmkcode.junit.MathTest" name="testDivide"/>
68+
<testcase time="0" classname="com.hmkcode.junit.MathTest" name="testMultiply"/>
69+
</testsuite>
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
-------------------------------------------------------------------------------
2+
Test set: com.hmkcode.junit.MathTest
3+
-------------------------------------------------------------------------------
4+
Tests run: 5, Failures: 0, Errors: 0, Skipped: 1, Time elapsed: 0.06 sec
Binary file not shown.

0 commit comments

Comments
 (0)