中的
ame中输入“HelloWorldTest”,在package中输入“ju
ittest”,然后单击“fi
ish”。
f(4)现在初步计划被测试文件功能非常简单,只有一个方法Retur
Value,作用是返回“HelloWorld”,所以测试类中有对Retur
Value这个方法进行测试的类。当然,测试要能进行,该测试类必须为主类,存在mai
方法。HelloWorldTestjava的源代码如下:
选择ru
ru
asJu
ittest弹出一个Ju
it窗口,发现在该窗口中有一个红条,这说明存在错误。(5)创建HelloWorld类建立一个HelloWorld类,并输入以下代码:
(6)在HelloWorldTestjava中加入importsrc此时以Ju
it测试的方式来运行HelloWorldTestjava,出现了含有绿色的窗
口,测试成功。
fassertEquals
publicstaticvoidassertEqualsjavala
gStri
gmessagejavala
gObjectexpectedjavala
gObjectactual
AssertsthattwoobjectsareequalIftheyare
ota
Assertio
Erroristhrow
withthegive
messageIfexpecteda
dactualare
ulltheyareco
sideredequal
Parameters
messagetheide
tifyi
gmessagefortheAssertio
Error
ullokayexpectedexpectedvalueactualactualvalue
assertFalse
publicstaticvoidassertFalsejavala
gStri
gmessageboolea
co
ditio
Assertsthataco
ditio
isfalseIfitis
titthrowsa
Assertio
Errorwiththegive
messageParameters
messagetheide
tifyi
gmessagefortheAssertio
Error
ullokayco
ditio
co
ditio
tobechecked
assertTrue
publicstaticvoidassertTruejavala
gStri
gmessageboolea
co
ditio
Assertsthataco
ditio
istrueIfitis
titthrowsa
Assertio
Errorwiththegive
messageParameters
messagetheide
tifyi
gmessagefortheAssertio
Error
ullokayco
ditio
co
ditio
tobechecked
assertNull
publicstaticvoidassertNulljavala
gStri
gmessagejavala
gObjectobject
Assertsthata
objectis
ullIfitis
ota
Assertio
Erroristhrow
withthegive
message
fParameters
messagetheide
tifyi
gmessagefortheAssertio
Error
ullokayobjectObjecttocheckor
ull
assertNotNull
publicstaticvoidassertNotNulljavala
gStri
gmessagejavala
gObjectobject
Assertsthata
objectis
t
ullIfitisa
Assertio
Erroristhrow
withthegive
messageParameters
messagetheide
tifyi
gmessagefortheAssertio
Error
ullokayobjectObjecttocheckor
ull
assertSame
publicstaticvoidassertSamejavala
gStri
gmessagejavala
gObjectexpectedjavala
gObjectactual
AssertsthattwoobjectsrefertothesameobjectIftheyare
ota
Assertio
Erroris
throw
withthegive
messageParameters
messagetheide
tifyi
gmessagefortheAssertio
Error
ullokayexpectedtheexpectedobjectactualtheobjecttocomparetoexpected
assertNotSame
publicstaticvoidassertNotSamejavala
gStri
gmessagejavala
gObjectu
expectedjavala
gObjectactual
Assertsthattwoobjectsr