天天看點

在Maven裡使用TestNG的方法的單元測試執行個體

<dependency>

<groupid>org.testng</groupid>

<artifactid>testng</artifactid>

<version>6.1.1</version>

<scope>test</scope>

</dependency>

  當然,這是對應的testng 6.1.1版本。其它版本的testng,應當隻需要改動一下版本号即可。

  在src/main/java檔案夾中書寫main.java檔案如下:

package org.silentmusicbox.justanothermavenproject;

public class main {

public string sayhello() {

return "hallo welt!";

}

public static void main(string [] args) {

main objofmain = new main();

system.out.println(objofmain.sayhello());

  在src/test/java檔案夾中書寫testmain.java檔案如下:

packageorg.silentmusicbox.justanothermavenproject;

importorg.testng.assert;

importorg.testng.annotations.beforemethod;

importorg.testng.annotations.test;

publicclasstestmain{

privatemainm;

@beforemethod

publicvoidinit(){

m=newmain();

@test

publicvoidtestsayhello(){

assert.assertequals(m.sayhello(),"hallowelt!");

最新内容請見作者的github頁:http://qaseven.github.io/