- Which built in module is used for unit testing in Python?
View Answer
Correct answer: A — unittest
- What will be printed?
1 python 2 import unittest 3 print(hasattr(unittest,"TestCase")) View Answer
Correct answer: A — True
- Which class is used to create test cases in unittest?
View Answer
Correct answer: A — TestCase
- What is the output of below code?
1 python 2 import unittest 3 class MyTest(unittest.TestCase): 4 def test_add(self): 5 self.assertEqual(2+3,5) 6 (Running test) View Answer
Correct answer: A — Pass
- Which method checks equality in unittest?
View Answer
Correct answer: A — assertEqual()
- What will be printed?
1 python 2 import unittest 3 class MyTest(unittest.TestCase): 4 def test_val(self): 5 self.assertEqual("Eduinq","Eduinq") 6 (Running test) View Answer
Correct answer: A — Pass
- Which method checks boolean true in unittest?
View Answer
Correct answer: A — assertTrue()
- What is the output of below code?
1 python 2 import unittest 3 class MyTest(unittest.TestCase): 4 def test_val(self): 5 self.assertTrue(5>2) 6 (Running test) View Answer
Correct answer: A — Pass
- Which method checks boolean false in unittest?
View Answer
Correct answer: A — assertFalse()
- What will be printed?
1 python 2 import unittest 3 class MyTest(unittest.TestCase): 4 def test_val(self): 5 self.assertFalse(2>5) 6 (Running test) View Answer
Correct answer: A — Pass
- Which method checks if object is None?
View Answer
Correct answer: A — assertIsNone()
- What is the output of below code?
1 python 2 import unittest 3 class MyTest(unittest.TestCase): 4 def test_val(self): 5 self.assertIsNone(None) 6 (Running test) View Answer
Correct answer: A — Pass
- Which method checks if object is not None?
View Answer
Correct answer: A — assertIsNotNone()
- What will be printed?
1 python 2 import unittest 3 class MyTest(unittest.TestCase): 4 def test_val(self): 5 self.assertIsNotNone("Eduinq") 6 (Running test) View Answer
Correct answer: A — Pass
- Which method checks if two objects are same?
View Answer
Correct answer: A — assertIs()
- What is the output of below code?
1 python 2 import unittest 3 class MyTest(unittest.TestCase): 4 def test_val(self): 5 a = b = "Eduinq" 6 self.assertIs(a,b) 7 (Running test) View Answer
Correct answer: A — Pass
- Which method checks if two objects are not same?
View Answer
Correct answer: A — assertIsNot()
- What will be printed?
1 python 2 import unittest 3 class MyTest(unittest.TestCase): 4 def test_val(self): 5 self.assertIsNot("Eduinq","Eduinq2") 6 (Running test) View Answer
Correct answer: A — Pass
- Which method checks if exception is raised?
View Answer
Correct answer: A — assertRaises()
- What is the output of below code?
1 python 2 import unittest 3 class MyTest(unittest.TestCase): 4 def test_val(self): 5 with self.assertRaises(ZeroDivisionError): 6 1/0 7 (Running test) View Answer
Correct answer: A — Pass
- Which method checks if two values are not equal in unittest?
View Answer
Correct answer: A — assertNotEqual()
- What will be printed?
1 python 2 import unittest 3 class MyTest(unittest.TestCase): 4 def test_val(self): 5 self.assertNotEqual(5,6) 6 (Running test) View Answer
Correct answer: A — Pass
- Which method checks if object is instance of class?
View Answer
Correct answer: A — assertIsInstance()
- What is the output of below code?
1 python 2 import unittest 3 class MyTest(unittest.TestCase): 4 def test_val(self): 5 self.assertIsInstance("Eduinq",str) 6 (Running test) View Answer
Correct answer: A — Pass
- Which method checks if object is not instance of class?
View Answer
Correct answer: A — assertNotIsInstance()
- What will be printed?
1 python 2 import unittest 3 class MyTest(unittest.TestCase): 4 def test_val(self): 5 self.assertNotIsInstance(5,str) 6 (Running test) View Answer
Correct answer: A — Pass
- Which of the following is used to group tests in unittest?
View Answer
Correct answer: A — TestSuite
- What is the output of below code?
1 python 2 import unittest 3 suite = unittest.TestSuite() 4 print(isinstance(suite,unittest.TestSuite)) View Answer
Correct answer: A — True
- Which of the following is used to discover tests in unittest?
View Answer
Correct answer: A — TestLoader
- What will be printed?
1 python 2 import unittest 3 loader = unittest.TestLoader() 4 print(hasattr(loader,"discover")) View Answer
Correct answer: A — True
- Which of the following is used to run tests in unittest?
View Answer
Correct answer: A — TextTestRunner
- What is the output of below code?
1 python 2 import unittest 3 runner = unittest.TextTestRunner() 4 print(callable(runner.run)) View Answer
Correct answer: A — True
- Which of the following is a third party testing framework in Python?
View Answer
Correct answer: A — pytest
- What will be printed?
1 python 2 import pytest 3 print(pytest.__name__) View Answer
Correct answer: A — pytest
- Which of the following is pytest's naming convention for test functions?
View Answer
Correct answer: A — test_*
- What is the output of below code?
1 python 2 def test_val(): 3 assert 2+3==5 4 (Running with pytest) View Answer
Correct answer: A — Pass
- Which of the following is used for fixtures in pytest?
View Answer
Correct answer: A — @pytest.fixture
- What will be printed?
1 python 2 import pytest 3 print(hasattr(pytest,"fixture")) View Answer
Correct answer: A — True
- Which of the following is used for parameterized tests in pytest?
View Answer
Correct answer: A — @pytest.mark.parametrize
- What is the output of below code?
1 python 2 import pytest 3 print(hasattr(pytest.mark,"parametrize")) View Answer
Correct answer: A — True
- Which of the following is used for skipping tests in pytest?
View Answer
Correct answer: A — @pytest.mark.skip
- What will be printed?
1 python 2 import pytest 3 print(hasattr(pytest.mark,"skip")) View Answer
Correct answer: A — True
- Which of the following is used for expected failure in pytest?
View Answer
Correct answer: A — @pytest.mark.xfail
- What is the output of below code?
1 python 2 import pytest 3 print(hasattr(pytest.mark,"xfail")) View Answer
Correct answer: A — True
- Which of the following is used for debugging in Python?
View Answer
Correct answer: A — pdb
- What will be printed?
1 python 2 import pdb 3 print(callable(pdb.set_trace)) View Answer
Correct answer: A — True
- Which of the following is used for doctest in Python?
View Answer
Correct answer: A — doctest
- What is the output of below code?
1 python 2 import doctest 3 print(hasattr(doctest,"testmod")) View Answer
Correct answer: A — True
- Which of the following is used for coverage in Python testing?
View Answer
Correct answer: A — coverage.py
- What will be printed?
1 bash 2 coverage run -m pytest View Answer
Correct answer: A — Runs tests with coverage