0% found this document useful (0 votes)
267 views

Python Qualis

The document discusses various topics related to software testing such as unit testing, integration testing, regression testing, test-driven development, and pytest. Some key points: - Unit testing tests individual components/units of a program and integration testing tests the interaction between units. - Test-driven development involves writing tests before writing code. - Pytest can discover and run tests written for unittest and nose test frameworks. It supports fixtures at function and package level. - The pytest command 'py.test' is used to discover and run tests in a project. The '-m junitxml' option generates a JUnit XML report.

Uploaded by

Ragav Endran
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
267 views

Python Qualis

The document discusses various topics related to software testing such as unit testing, integration testing, regression testing, test-driven development, and pytest. Some key points: - Unit testing tests individual components/units of a program and integration testing tests the interaction between units. - Test-driven development involves writing tests before writing code. - Pytest can discover and run tests written for unittest and nose test frameworks. It supports fixtures at function and package level. - The pytest command 'py.test' is used to discover and run tests in a project. The '-m junitxml' option generates a JUnit XML report.

Uploaded by

Ragav Endran
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 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

The discipline of writing tests first and then writing development code is known as
____________.
Test Driven development

Which type of testing is performed to check if a program is behaving as expected?


acceptance testing

The process of evaluating a software with an intent to determine if it has met the
specified requirements is known as __________.
Software Testing
===================================================================================
============================================
1. Which of the following is a valid doctest?
def add(x,y):
"""Returns sum of two numbers.
>>>add(5,6)
13
"""
return x+y

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

def sample_func(x, y):


"""Multiplies two given numbers and returns the product.
"""
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?
#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.

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


Output stating 2 failures

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?
__doc__

9.Which of the following doctest directive is used for not considering or executing
a specific doctest?
#doctest: +SKIP

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


True

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

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')

def test_sample2(self):
self.assertRaises(Exception, max, [7, 8, '4'])

def test_sample3(self):
self.assertRaises(ValueError, int, 'hello')
0

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

import unittest

def test_sample1():
assert 3 == 3

class SampleTestClass(unittest.TestCase):

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

Which of the following statement ensures that all tests present in


sample_test_module.py are run while using the command python sample_test_module.py
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())

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?
assertRegexpMatches

Which is the expected output of below code, when run using command python -m
unittest sample_module.py

import unittest

class SampleTestClass(unittest.TestCase):

def setUpClass(cls):
print('Entering Test Class')

def tearDownClass(cls):
print('Exiting Test Class')

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

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
execute them using nose?
nosetests

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:

@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):

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

Which of the following package is required for generating test reports in html
format using nose?
nose-htmloutput

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


True

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?
@timed
ok_ utility from nose.tools is equivalent to ____________.
assert

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


True

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

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

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


False

Which of the following option is used to generate Junit style test report in xml
using pytest?
--junitxml

Which of the following decorator is used to skip a test unconditionally, with


pytest?
@pytest.mark.skip

You might also like