Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the methods of the TestNG Assert class

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

TestNG Assert class method is what, for this problem, this article details the corresponding analysis and solution, hoping to help more small partners who want to solve this problem to find a simpler and easier way.

package com.testng.examples;

import org.testng.Assert;

import org.testng.annotations.Test;

public class AssertTest {

@Test

public void test() {

/**

* Assert#assertEquals

*

* The assertEquals method compares assertions against all data types in Java.

* 2. Basic data types directly perform value comparison and assertion

* 3. Wrapper classes and custom data types inherited from Object are compared using the equals method

* Set type data is compared using the equals method of the class (Set class overrides the equals method of Object)

* 5. Other Collection data, such as List data, iterates through all elements in order and compares them using the equals method.

* 6. Array type data, traverse the elements in the array, and compare them through the equals method of the element type. If the array element is a primitive data type, use the value comparison.

*/

/*

Assert.assertEquals(actual, expected);

Assert.assertEquals(actual, expected, message);

Assert.assertEquals(actual, expected, delta);

Assert.assertEquals(actual, expected, delta, message);

*/

//compares map data types, comparing array elements in map elements sequentially

//Assert.assertEqualsDeep(null, null);

//Used to compare set data types. This method iterates over all elements in set elements. If Set data is array type, it compares array elements in order.

//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

//Asserts that two arrays contain the same elements and ignores the order of array elements

Assert.assertEqualsNoOrder(a, b);

//assert two bool type data

Assert.assertFalse(false);

Assert.assertTrue(true);

//Asserts whether Object type data is null

Assert.assertNull(null);

Assert.assertNotNull(new Object());

//Asserts whether two objects refer to the same object

//ssert.assertSame(new Integer(1), new Integer(1));//failed

Assert.assertNotSame(new Integer(1), new Integer(1));//success

//asserts that an executable program has an exception thrown

Assert.assertThrows(()->{throw new RuntimeException();});//success

//Assert.assertThrows(NullPointerException.class, ()->{throw new RuntimeException();}); //failed

//custom assertion failed

//Assert.fail("Test execution failed cased by somthing reason. ");

}

}

About TestNG Assert class method is what kind of answer to the question shared here, I hope the above content can have some help to everyone, if you still have a lot of doubts not solved, you can pay attention to the industry information channel to learn more related knowledge.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report