Saturday, September 21, 2024

Assertions TestNG MCQ

 Here are some multiple-choice questions (MCQs) focused on assertions in TestNG, which are used to validate conditions in test methods to ensure they behave as expected.


1. What is the primary purpose of assertions in TestNG?

A) To generate test data dynamically

B) To validate that the application under test is working as expected

C) To skip the execution of certain test methods

D) To control the order of test method execution


Answer: B) To validate that the application under test is working as expected


2. Which TestNG assertion is used to check whether two values are equal?

A) Assert.assertTrue()

B) Assert.assertFalse()

C) Assert.assertEquals()

D) Assert.assertNotNull()


Answer: C) Assert.assertEquals()


3. What will happen if an assertion fails in a TestNG test method?

A) The test method will be skipped

B) The test method will pass with a warning

C) The test method will fail and execution will stop immediately

D) The test suite will halt execution


Answer: C) The test method will fail and execution will stop immediately


4. Which assertion is used to verify that a particular object is null in TestNG?

A) Assert.assertTrue()

B) Assert.assertNull()

C) Assert.assertNotNull()

D) Assert.assertEquals()


Answer: B) Assert.assertNull()


5. How can you provide a custom error message in a TestNG assertion?

A) Assert.assertTrue(condition, "Custom error message");

B) Assert.fail("Custom error message", condition);

C) Assert.assertEquals(condition, "Custom error message");

D) Assert.assertTrue("Custom error message", condition);


Answer: A) Assert.assertTrue(condition, "Custom error message");


6. Which of the following assertions checks that two objects do not refer to the same object?

A) Assert.assertEquals()

B) Assert.assertSame()

C) Assert.assertNotSame()

D) Assert.assertNotEquals()


Answer: C) Assert.assertNotSame()


7. Which assertion would you use to check that a condition is false in TestNG?

A) Assert.assertTrue(false)

B) Assert.assertFalse(condition)

C) Assert.assertNotNull()

D) Assert.assertEquals(false)


Answer: B) Assert.assertFalse(condition)


8. What does Assert.fail() do in TestNG?

A) It passes the test method regardless of the conditions

B) It stops the test suite execution

C) It immediately fails the test method

D) It skips the test method


Answer: C) It immediately fails the test method


9. Which assertion method checks if two arrays are equal in TestNG?

A) Assert.assertEquals()

B) Assert.assertArrayEquals()

C) Assert.assertSame()

D) Assert.assertArraysEquals()


Answer: B) Assert.assertArrayEquals()


10. What is the difference between Assert.assertEquals() and Assert.assertSame() in TestNG?

A) Assert.assertEquals() checks for object reference equality, while Assert.assertSame() checks for value equality

B) Assert.assertEquals() checks for value equality, while Assert.assertSame() checks for object reference equality

C) Both methods perform the same function

D) Assert.assertSame() is not a valid TestNG method


Answer: B) Assert.assertEquals() checks for value equality, while Assert.assertSame() checks for object reference equality



12. What assertion would you use to validate that two values are not equal in TestNG?

A) Assert.assertTrue()

B) Assert.assertNotEquals()

C) Assert.assertFalse()

D) Assert.assertNull()


Answer: B) Assert.assertNotEquals()


13. Which TestNG assertion checks if a condition is true and provides a failure message if it is not?

A) Assert.assertTrue(condition)

B) Assert.assertFalse(condition)

C) Assert.assertTrue(condition, "Failure message")

D) Assert.assertFalse(condition, "Failure message")


Answer: C) Assert.assertTrue(condition, "Failure message")


14. How can you assert that two lists have the same elements in TestNG?

A) Assert.assertEquals(list1, list2)

B) Assert.assertSame(list1, list2)

C) Assert.assertListsEqual(list1, list2)

D) Assert.assertEqualElements(list1, list2)


Answer: A) Assert.assertEquals(list1, list2)


15. What assertion should you use to verify an object is not null in TestNG?

A) Assert.assertTrue()

B) Assert.assertNull()

C) Assert.assertNotNull()

D) Assert.assertFalse()


Answer: C) Assert.assertNotNull()

No comments:

Post a Comment

git commands MCQ

 Here are some multiple-choice questions (MCQs) on Git commands relevant for Selenium: 1. Which Git command is used to clone a remote reposi...