TestNG Tutorial
Introduction to TestNG Configuration and set up of TestNG project Simple TestNG project in IntelliJ IDEA TestNG annotations Assertions in TestNG Difference between assertEquals and assertSame Ignoring the tests in TestNG Grouping the tests timeOut tests in TestNG Exception tests in TestNG dependsOnMethods dependsOnGroups Hard and Soft dependencies Passing parameters using XML file Passing parameters using Data providers Dynamic Data Providers group-by-instances attribute in TestNG XML suite file Test priorities in TestNG invocationCount in TestNG Executing Selenium tests using TestNG Executing TestNG tests using main method Executing JUnit tests from within TestNG Running tests in Parallel in TestNG Executing only failed tests in TestNG TestNG integration with Maven TestNG integration with Gradle Reporter class in TestNG TestNG Reports Execution Listener Test Listener Comparison between JUnit and TestNGAssertions in testng
Assertions related methods are put in org.testng.Assert class. We have below methods to assert in out tests- Assert.assertEquals
- Assert.assertFalse
- Assert.assertTrue
- Assert.assertNull
- Assert.assertNotNull
- Assert.assertSame
- Assert.assertNotSame
- Assert.fail
package org.softpost;
import org.testng.Assert;
import org.testng.annotations.Test;
public class TestNGAssertions {
@Test
public void testAssertions(){
String x=null;
Assert.assertEquals(2,2,"equality test");
Assert.assertNotEquals(2, 3, "Inequality test");
Assert.assertTrue(2==2);
Assert.assertFalse(2 == 1);
Assert.assertNull(x, "Checking if x is null");
Assert.assertNotNull("Watson","Checking that watson is not null");
TestNGAssertions t1= new TestNGAssertions();
TestNGAssertions t2= t1;
//Below will pass as t1 and t2 refer to same objects
Assert.assertSame(t1,t2);
TestNGAssertions t3= new TestNGAssertions();
TestNGAssertions t4= new TestNGAssertions();
Assert.assertEquals(t3,t4);
//Below will fail as t3 and t4 refer to different objects not same
Assert.assertSame(t3,t4);
Assert.fail("Fail the test");
}
}
Web development and Automation testing
solutions delivered!!