1
<?xml version="1.0"?>
2
<project name="anttest" default="run">
3
<property name="build.path" value="build/classes/"/>
4
<path id="compile.classpath">
5
<fileset dir="lib">
6
<include name="*.jar"/>
7
</fileset>
8
</path>
9
10
<target name="init">
11
<mkdir dir="${build.path}" />
12
<mkdir dir="dist" />
13
</target>
14
<target name="compile" depends="init">
15
<javac srcdir="src/" destdir="${build.path}" classpath="${build.path}">
16
<classpath refid="compile.classpath"/>
17
</javac>
18
<echo>compilation complete!</echo>
19
</target>
20
<target name="run" depends="compile">
21
<java classname="org.test.work.HelloWorld" classpath="${build.path}" />
22
<echo>Run complete!</echo>
23
</target>
24
25
<target name="test" depends="compile">
26
<junit printsummary="on" haltonfailure="true" showoutput="true">
27
<classpath refid="compile.classpath"/>
28
<classpath path="${build.path}"/>
29
<formatter type="xml" />
30
<test name="org.test.work.HelloWorldTest"/>
31
</junit>
32
</target>
33
34
</project>

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

HelloWorld.java
1
package org.test.work;
2
3
public class HelloWorld{
4
5
public String showMessage(){
6
return "Hello world!!!";
7
}
8
9
public static void main(String[] args){
10
11
System.out.println("Hello world!!!");
12
}
13
}

2

3

4

5

6

7

8

9

10

11

12

13

HelloWorldTest.java
1
package org.test.work;
2
3
import static org.junit.Assert.*;
4
import org.junit.*;
5
6
import org.test.work.HelloWorld;
7
8
public class HelloWorldTest{
9
10
private static HelloWorld hw = null;
11
12
@BeforeClass
13
public static void setUp(){
14
hw = new HelloWorld();
15
}
16
17
@Test
18
public void showHelloWorld(){
19
assertEquals(hw.showMessage(),"Hello world!!!");
20
}
21
22
@AfterClass
23
public static void tearDown(){
24
hw = null;
25
}
26
27
}

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27
