Download as pdf or txt
Download as pdf or txt
You are on page 1of 6

The real objective of Software testing is to ensure 100% defect free product.

State true or false.


False

Which of the following is the next level of testing to unit testing?


Integration testing

Which of the following are the unit testing packages availabale in Python?
All of those mentioned

The testing method, which is used to test individual components of a program is


known as ________.
Unit testing

Why Software Testing is necessary?


All of those mentioned

Unit Testing is the highest level of testing. State true or false.


False

Which type of testing is done when one of your existing functions stop working?
regression testing

m
er as
The discipline of writing tests first and then writing development code is known

co
as ____________.

eH w
Test Driven development

o.
Which type of testing is performed to check if a program is behaving as
rs e
expected?
ou urc
acceptance testing

The process of evaluating a software with an intent to determine if it has met


the specified requirements is known as __________.
o

Software Testing
aC s

================================================================================
v i y re

===============================================
1. Which of the following is a valid doctest?
def add(x,y):
"""Returns sum of two numbers.
>>>add(5,6)
ed d

13
ar stu

"""
return x+y

2.A sample function sample_fuc is defined as shown below.


sh is

def sample_func(x, y):


"""Multiplies two given numbers and returns the product.
Th

"""
print(x)
print()
print(y)
print()
print(x*y)
Which of the following doctest correctly tests it's functionality?
>>> sample_func(6,7)
6
<BLANKLINE>
7
<BLANKLINE.
42

3.Which of the following doctest directive is used to deal with unexpected


whitespace that appears in the output?

This study source was downloaded by 100000790328255 from CourseHero.com on 06-27-2021 13:10:38 GMT -05:00

https://www.coursehero.com/file/38323060/Python-Qualistxt/
#doctest: +NORMALIZE_WHITESPACE

4.Which of the following is a docstring?


A Multiline string

5.A sample module named sample_module.py contained the following contents.

def mul(x, y):


"""Multiplies two given numbers and returns the product.
>>> mul(6, 7)
42
>>> mul(-8, 7)
-56
"""
return x * y
What is the expected output when you run the doctests using below command?

python -m doctest sample_module.py


No output

6. A sample module named sample_module.py contained the following contents.

m
def mul(x, y):

er as
"""Multiplies two given numbers and returns the product.

co
>>> mul(6, 7)

eH w
42
>>> mul(-8, 7)

o.
>>> -56 rs e
"""
ou urc
return x * y
What is the expected output when you run the doctests using below command?

python -m doctest sample_module.py


o

Output stating 2 failures


aC s
v i y re

7.Which of the following doctest directive is used to ignore part of the result?
#doctest: +ELLIPSIS

8.Which of the following special attribute can be used to access a doc string in
a program?
ed d

__doc__
ar stu

9.Which of the following doctest directive is used for not considering or


executing a specific doctest?
#doctest: +SKIP
sh is

10.A doctest mixes documentation and testing. State true or false.


True
Th

11.Which of the following is true about a docstring?


docstring is optional in a function, class or a module
================================================================================
=========================================
Which of the following commands run only one test case , present in
sample_module.py using unittest?
python -m unitest sample_module.TestCase1.test_method1

What is the parent class from which a Test class has to be derived for running
it with unittest?
unittest.TestCase

unittest is a xUnit-style based unit testing framework in Python. State true or


false.
True

This study source was downloaded by 100000790328255 from CourseHero.com on 06-27-2021 13:10:38 GMT -05:00

https://www.coursehero.com/file/38323060/Python-Qualistxt/
Which of the following method is used to catch exceptions in a test, with
unittest?
assertRaises

A single test module contains only one Test Class. State true or false.
False

Which of the following decorator is used to skip a test if a given condition is


false, with unittest?
unittest.skipUnless

How many tests of sample_module.py shown below, are successfully passed, when
run with unittest?

import unittest

class SampleTestClass(unittest.TestCase):

def test_sample1(self):
self.assertRaises(TypeError, pow, 2, '4')

m
er as
def test_sample2(self):

co
self.assertRaises(Exception, max, [7, 8, '4'])

eH w
def test_sample3(self):

o.
self.assertRaises(ValueError, int, 'hello')
rs e
0
ou urc
How many tests are run, when below code is tested using unittest

import unittest
o
aC s

def test_sample1():
v i y re

assert 3 == 3

class SampleTestClass(unittest.TestCase):
ed d
ar stu

def test_sample2(self):
self.assertEqual(3, 3)
1

Which of the following statement ensures that all tests present in


sh is

sample_test_module.py are run while using the command python


sample_test_module.py
Th

unittest.main

Test methods are executed alphabetically. State true or false.


True

What is the purpose of using self.id in tests, while working with unittest?
self.id returns the name of the method

How many tests are run, when below code is tested using unittest

import unittest

class SampleTestClass(unittest.TestCase):

def sample_test1(self):
self.assertEqual('HELLO', 'hello'.upper())

This study source was downloaded by 100000790328255 from CourseHero.com on 06-27-2021 13:10:38 GMT -05:00

https://www.coursehero.com/file/38323060/Python-Qualistxt/
def test_sample2(self):
self.assertEqual(3*3, 9)
1

Which of the following method is used to check equality of two lists in a test,
with unitest?
assertListEqual

Which of the following command is execute to run all the test cases present in a
project folder using unittest?
python -m unittest discover

Which of the following decorator need to be used while working with setUpClass
and tearDownClass fixtures?
@classmethod

Which of the following are the module level fixtures of unittest framework?
setUpModule, tearDownModule

Which of the following method is used to check if a regular expression matches a


string or not, with unittest?

m
assertRegexpMatches

er as
co
Which is the expected output of below code, when run using command python -m

eH w
unittest sample_module.py

o.
import unittest rs e
ou urc
class SampleTestClass(unittest.TestCase):

def setUpClass(cls):
print('Entering Test Class')
o
aC s

def tearDownClass(cls):
v i y re

print('Exiting Test Class')

def test_sample1(self):
self.assertEqual(3*3, 9)
The test run fails
ed d
ar stu

Which of the following is not a component of Xunit-Style Architecture?


Test Loader
================================================================================
=======================================================
Which of the following command is used to discover all tests in a project and
sh is

execute them using nose?


nosetests
Th

Which of the following decorator is used to assign user defined setup and tear
down functions to a test function, while using nose?
@with_setup

nose can recognise tests which are not part of a Test class, derived from a
Parent class. State True or False
True

How many tests of sample_module.py shown below, are successfully passed, when
run with nose?

from nose.tools import raises

class SampleTestClass:

This study source was downloaded by 100000790328255 from CourseHero.com on 06-27-2021 13:10:38 GMT -05:00

https://www.coursehero.com/file/38323060/Python-Qualistxt/
@raises(TypeError)
def test_sample1(self):
pow(2, '4')

@raises(Execption)
def test_sample2(self):
max([7, 8, '4'])

@raises(Exception)
def test_sample3(self):
int('hello')
1

How many tests are run, when below code is tested using nose?

import unittest

def test_sample1():
assert 3 == 3

class SampleTestClass(unittest.TestCase):

m
er as
co
def test_sample2(self):

eH w
self.assertEqual(3, 3)
0

o.
rs e
Which of the following package is required for generating test reports in html
ou urc
format using nose?
nose-htmloutput

Unittest Tests can be run using nose. State true or false.


o

True
aC s
v i y re

Test discovery is simpler in unittest than in nose. State true or false.


False

Which of the following decorator is used to report a test as a failure one, if


execution of it takes more than the specified number of seconds?
ed d

@timed
ar stu

ok_ utility from nose.tools is equivalent to ____________.


assert

nose supports use of fixtures at package level. State true or false.


sh is

True
Th

Which of the following option is used to generate test report in xml using nose?
--with-xunit
================================================================================
======================================
Which of the following commands run only one test case, present in
sample_module.py using pytest?
py.test sample_module.py::TestCase1::test_method1

Which of the following decorator is used to transform a user defined function


into a fixture using pytest?
@pytest.fixture

Which of the following command is used to discover all tests in a project and
execute them using pytest?
py.test

This study source was downloaded by 100000790328255 from CourseHero.com on 06-27-2021 13:10:38 GMT -05:00

https://www.coursehero.com/file/38323060/Python-Qualistxt/
Which of the following are the function level fixtures available in pytest?
setup_function,teardown_function

How many tests are run, when below code is tested using pytest

import unittest

def test_sample1():
assert 3 == 3

class SampleTestClass(unittest.TestCase):

def test_sample2(self):
self.assertEqual(3, 3)
2

pytest is capable of discovering and running tests written in unittest and nose.
State true or false.
True

m
pytest is available as a part of Python standard library. State true or false.

er as
False

co
eH w
Which of the following option is used to generate Junit style test report in xml
using pytest?

o.
--junitxml rs e
ou urc
Which of the following decorator is used to skip a test unconditionally, with
pytest?
@pytest.mark.skip
o
aC s
v i y re
ed d
ar stu
sh is
Th

This study source was downloaded by 100000790328255 from CourseHero.com on 06-27-2021 13:10:38 GMT -05:00

https://www.coursehero.com/file/38323060/Python-Qualistxt/
Powered by TCPDF (www.tcpdf.org)

You might also like