TestNG Assert類方法是怎樣的,針對這個(gè)問題,這篇文章詳細(xì)介紹了相對應(yīng)的分析和解答,希望可以幫助更多想解決這個(gè)問題的小伙伴找到更簡單易行的方法。
成都創(chuàng)新互聯(lián)專注于網(wǎng)站建設(shè),為客戶提供網(wǎng)站設(shè)計(jì)、成都網(wǎng)站制作、網(wǎng)頁設(shè)計(jì)開發(fā)服務(wù),多年建網(wǎng)站服務(wù)經(jīng)驗(yàn),各類網(wǎng)站都可以開發(fā),成都品牌網(wǎng)站建設(shè),公司官網(wǎng),公司展示網(wǎng)站,網(wǎng)站設(shè)計(jì),建網(wǎng)站費(fèi)用,建網(wǎng)站多少錢,價(jià)格優(yōu)惠,收費(fèi)合理。
package com.testng.examples;
import org.testng.Assert;
import org.testng.annotations.Test;
public class AssertTest {
@Test
public void test() {
/**
* Assert#assertEquals
*
* 1.assertEquals方法可對java中所有數(shù)據(jù)類型進(jìn)行斷言比較。
* 2.基本數(shù)據(jù)類型直接進(jìn)行值比較進(jìn)行斷言
* 3.包裝類及自定義繼承自O(shè)bject的數(shù)據(jù)類型則使用equals方法進(jìn)行比較
* 4.Set類型數(shù)據(jù)使用類的equals方法進(jìn)行比較(Set類已復(fù)寫Object的equals方法)
* 5.其他Collection類型數(shù)據(jù),比如List類型數(shù)據(jù),則按順序遍歷所有元素,并使用equals方法進(jìn)行比較
* 6.數(shù)組類型數(shù)據(jù),遍歷數(shù)組中各元素,并通過元素類型的equals方法進(jìn)行比較,如果數(shù)組元素為基本數(shù)據(jù)類型則使用值比較
*/
/*
Assert.assertEquals(actual, expected);
Assert.assertEquals(actual, expected, message);
Assert.assertEquals(actual, expected, delta);
Assert.assertEquals(actual, expected, delta, message);
*/
//用于對map數(shù)據(jù)類型進(jìn)行比較,該方法會對map元素中數(shù)組各元素按順序比較
//Assert.assertEqualsDeep(null, null);
//用于對set數(shù)據(jù)類型進(jìn)行比較,該方法會遍歷set元素中所有元素,且Set數(shù)據(jù)為數(shù)組類型時(shí),會對數(shù)組各元素按順序比較
//Assert.assertEqualsDeep(actual, expected, message);
String[] a = new String[]{"a3","a1","a2"};
String[] a1 = new String[]{"a3","a1","a2"};
String[] b = new String[]{"a1","a2","a3"};
Assert.assertEquals(a, a1);
Assert.assertNotEquals(a, b);
System.out.println(a.equals(a1));//true
//斷言兩個(gè)數(shù)組包含相同元素,并且忽略數(shù)組元素的排列順序
Assert.assertEqualsNoOrder(a, b);
//斷言兩個(gè)bool類型數(shù)據(jù)
Assert.assertFalse(false);
Assert.assertTrue(true);
//斷言O(shè)bject類型數(shù)據(jù)是否為null
Assert.assertNull(null);
Assert.assertNotNull(new Object());
//斷言兩個(gè)對象是否引用同一個(gè)對象
//ssert.assertSame(new Integer(1), new Integer(1));//failed
Assert.assertNotSame(new Integer(1), new Integer(1));//success
//斷言一段可執(zhí)行程序有異常拋出
Assert.assertThrows(()->{throw new RuntimeException();});//success
//Assert.assertThrows(NullPointerException.class, ()->{throw new RuntimeException();}); //failed
//自定義斷言失敗
//Assert.fail("Test execution failed cased by somthing reason.");
}
}
關(guān)于TestNG Assert類方法是怎樣的問題的解答就分享到這里了,希望以上內(nèi)容可以對大家有一定的幫助,如果你還有很多疑惑沒有解開,可以關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道了解更多相關(guān)知識。
分享名稱:TestNGAssert類方法是怎樣的
轉(zhuǎn)載注明:http://jinyejixie.com/article22/pgigcc.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站導(dǎo)航、網(wǎng)站策劃、網(wǎng)站排名、ChatGPT、網(wǎng)站改版、營銷型網(wǎng)站建設(shè)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)