Eclipse版本:
Eclipse Java EE IDE for Web Developers.
Version: Helios Release
Testng版本:
5.13
步骤
1.Eclipse中点击Help->Install new software
2.点击Add 在Location输入 http://beust.com/eclipse

3.选中Testng版本,点击Next,按照提示安装,安装完之后重启Eclipse
4.新建JavaProject,右键BuildPath,添加testng-5.11-jdk15.jar和eclipse-testng.jar
5.新建一个sum类,用来计算两整数之和,代码如下:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
|
package
com
.
hpp
;
public
class
sum
{
private
int
no1
;
private
int
no2
;
private
int
mysum
;
public
int
add
(
int
no1
,
int
no2
)
{
mysum
=
no1
+
no2
;
return
mysum
;
}
}
|
6.再新建testng class

点击finish,代码如下
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
|
package
com
.
test
;
import
org
.
testng
.
annotations
.
Test
;
import
static
org
.
testng
.
Assert
.
assertEquals
;
import
com
.
hpp
.
sum
;
public
class
NewTest
{
private
sum
newSum
=
new
sum
(
)
;
@Test
public
void
f
(
)
{
int
mysum
=
newSum
.
add
(
1
,
2
)
;
assertEquals
(
3
,
mysum
,
"Right"
)
;
}
}
|
testing,xml会自动配置好的,这里不用管
项目的文件结构如下:

7.在testing.xml右键点击RunAs->Testng Suite,即可看到结果

至于selenium 2 的jar包只需要直接的项目中导入即可了