UNIT 5
Coding & Software Testing
Q1) What is reliability and metrics to reliability?
A1)
Software reliability is also defined as the probability that a software system fulfils its assigned task in a given environment for a predefined number of input cases, assuming that the hardware and the inputs are free of error.
“It is the probability of a failure free operation of a program for a specified time in a specified environment”
Reliability metrics are used to quantitatively express the reliability of the software product. The option of which metric is to be used depends upon the type of system to which it applies & the requirements of the application domain. Some reliability metrics which can be used to quantify the reliability of the software product are as follows:
Requirements are a means of establishing a written agreement between user and software developer that a system will be designed with such required features. Requirement Reliability metrics calculates quality factors of the required document.
The reliability metric of code and design will evaluate the program on complexity, size, and modularity. Complex modules are not welcomed as there is a high probability of occurring bugs. The reliability will reduce if modules have a combination of high complexity and large size or high complexity and small size.
These metrics use two methods to calculate reliability. First, it provides that the system is equipped with the tasks that are specified in the requirements. Because of this, the bugs due to the lack of functionality reduces.
The second method is calculating the code, finding the bugs & fixing them. To ensure that the system includes the functionality specified, test plans are written that include multiple test cases.
Q2) Consider a program for the determination of the nature of roots of a quadratic equation Its input is a triple of positive integers (say a,b,c) and values may be from interval [0,100] The program output may have one of the following words[Not a quadratic equation; Real roots; Imaginary roots; Equal roots]. Design the boundary value test cases?
Quadratic equation will be of type:
ax2+bx+c=0
Roots are real if (b2-4ac)>0
Roots are imaginary if (b2-4ac) <0
Roots are equal if (b2-4ac) =0
Equation is not quadratic if a=0
The boundary value test cases are:
Q3) Consider a flow graph given below and calculate the Cyclomatic complexity by all three methods?
A3)
Cyclomatic complexity can be calculated by any of the three methods
1.V(G) = e – n + 2P
= 13 – 10 + 2 = 5
2.V(G) = π + 1
= 4 + 1 = 5
3.V(G) = number of regions
= 5
Therefore, complexity value of a flow graph is 5.
Q4) What is Unit Testing? Explain in detail?
A4)
Unit testing is performed to test the individual units of software. As software is made of a number of units/modules, detecting errors in these units is simple and consumes less time, as they are small in size. However, it is possible that the outputs produced by one unit become input for another unit. Hence, if incorrect output produced by one unit is providedas input to the second unit, then it also produces wrongoutput. To avoid this, all the units in software are tested independently using unit testing.
Unit level testing is performed many times during the software development, rather it is repeated whenever software is modified or used in a new environment. The other points noted about unit testing are listed below:
• Each unit is tested in isolation from other parts of a program.
• The developers themselves perform unit testing.
• Unit testing makes use of white box testing methods.
Types of Unit Testing: The various tests that are performed as a part of unit testing are listed below:
• Module interface: These are tested to ensure that information flows in a proper manner into and out of the ‘unit’ under test. Note that test of data flow (across a module interface) is required before any other test is initiated.
• Local data structure: These are tested to ensure that the temporarily stored data maintains its integrity while an algorithm is being executed.
Boundary conditions: These are tested to ensure that the module operates as desired within the specified boundaries.
• All independent paths: These are tested to ensure that all statements in a module have been executed at least once. Note that in this testing, the entire control structure should be exercised.
• Error handling paths: After successful completion of the various tests, error-handling paths are tested.
Q5) Explain Integration Testing and its importance?
A5)
After unit testing is completed, integration testing begins. In integration testing, the units validated during unit testing are combined to form a sub system. The purpose of integration testing is to ensure that all the modules continue to work in accordance with user/customer requirements even after integration.
The objective of integration testing is to take all the tested individual modules, integrate them, test them again, and develop the software, which is according to design specifications.
Integration testing is done for further more reasons:
• It ensures that all modules work together properly, are called correctly, and transfer accurate data across their interfaces.
• itis performed with an intention to expose defects in the interfaces and in the
Interactions between integrated components or systems.
• Integration testing examines the components that are new, changed, affected by a change, or needed to form a complete system.
Q6) What is user acceptance testing?
A6)
User Acceptance Testing is a kind of testing in software development in which the software is tested in the” real world" by the intended users. User acceptance testing is used to know if the system is working or not (both clients & in-house)
Different user acceptance testing are:
Alpha Testing
Alpha testing is the software prototype stage when the software is first able to run. It will not have all the intended functionality, but it will have core functions and will be able to accept inputs and generate outputs. An alpha test usually takes place in the developer's offices on a separate system.
Beta Testing
The beta phase of software design exposes a new product, which has just emerged from in-house (alpha) testing, to a large number of real people, real hardware, and real usage. Beta testing is not a method of getting free software long-term, because the software expires shortly after the testing period.
Q7) What is White Box Testing? Give its advantage and disadvantages?
A7)
White box testing, also known as structural testing is performed to check the internalstructure of a program. To perform white box testing, tester should have thoroughknowledge of the program code and the purpose for which it is developed. The basicstrength of this testing is that the entire software implementation is included while testing isperformed. This facilitates error detection even when the software specification is vagueor incomplete.
The objective of white box testing is to ensure that the test cases (developed by software. Testers by using white box testing) exercise each path through a program. That is, test cases ensure that all internal structures in the program are developed according to design specifications. The test cases also ensure that:
• All independent paths within the program have been executed at least once.
• All internal data structures are exercised to ensure validity.
• All loops (simple loops, concatenated loops, and nested loops) are executed at theirboundaries and within operational bounds.
• All the segments present between the controls structures (like ‘switch’ statement) areexecuted at least once.
• Each branch (like ‘case’ statement) is exercised at least once.
• All the branches of the conditions and the combinations of these conditions are executedat least once. Note that for testing all the possible combinations, a ‘truth table’ is usedwhere all logical decisions are exercised for both true and false paths.
The various types of testing, which occur as part of white box testing are basis path testing, controlstructure testing, and mutation testing.
Advantages | Disadvantages |
Covers the larger part of the program code while testing. | Tests that cover most of the program code may not be good for assessing the functionality of surprise (unexpected) behaviours and other testing goals. |
Uncovers typographical errors. | Tests based on design may miss other system problems. |
Detects design errors that occur when incorrect assumptions are made about execution paths. | Tests cases need to be changed if implementation changes. |
Q8) What is Black box testing? Explain in detail?
A8)
Black box testing, also known as functional testing, checks the functional requirements and examines the input and output data of these requirements. The functionality is determined by observing the outputs to corresponding inputs. For example, when black box testing is used, the tester should only know the ‘legal’ inputs and what the expected outputs should be, but not how the program actually arrives at those outputs.
The black box testing is used to find errors listed below:
In this testing, various inputs are exercised and the outputs are compared against specification to validate the correctness. Note that test cases are derived from these specifications without considering implementation details of the code. The outputs are compared with user requirements and if they are as specified by the user, then the software is considered to be correct, elsese the software is tested for the presence of errors in it.
Advantages | Disadvantages |
Tester requires no knowledge of implementation and programming language used. | Only small number of possible inputs can be tested as testing every possible input consumes a lot of time. |
Reveals any ambiguities and inconsistencies in the functional specifications. | There can be unnecessary repetition of test inputs if the tester is not informed about the test cases that software developer has already tried. |
Efficient when used on larger systems. | Leaves many program paths untested. |
Non-technical person can also perform black box Testing. | Cannot be directed towards specific segments of code, hence is more error prone. |
Q9) Define Structural Testing and Path Testing?
A9)
Structural Testing
A complementary approach to functional testing is called structural / white box
testing. It permits us to examine the internal structure of the program.
Path Testing
Path testing is the name given to a group of test techniques based on judiciously
selecting a set of test paths through the program. If the set of paths is properly
chosen, then it means that we have achieved some measure of test thoroughness.
This type of testing involves:
1. Generating a set of paths that will cover every branch in the program.
2. Finding a set of test cases that will execute every path in the set of program
Paths.
Q10) Calculate the Cyclomatic Complexity flow graph shown below with entry node ‘a’ and exit node ‘f’?
A10) The value of Cyclomatic complexity can be
Calculated as :
V(G) = 9 – 6 + 2 = 5
Here e = 9, n = 6 and P =1
There will be five independent
paths for theflow graph
Path 1 : a c f
Path 2 : a b e f
Path 3 : a d c f
Path 4 : a b e a c f or a b e a b e f
Path 5 : a b e b e f
Q11) Differentiate between Black box and White box testing?
A11)
Solution: | White box | Black box |
Purpose | It is used to test the internal structure of software. | It is used to test the functionality of software. |
| It is concerned only with testing software and does not guarantee the Complete implementation of all the specifications mentioned in userrequirements. | It is concerned only with testing specifications and does not guarantee that all the components of software that are implemented are tested. |
| It addresses flow and control structureof a program. | It addresses validity, behaviour and performance of software. |
Stage | It is performed in the early stages oftesting. | It is performed in the later stages of testing. |
Requirement | Knowledge of the internal structure ofa program is required for generating test case. | No knowledge of the internal structure of a program is required to generate test case. |
Test Cases | Here test cases are generated based onthe actual code of the module to be tested. | Here the internal structure of modules or programs is not considered for selecting test cases. |
| The inner software present inside thecalculator (which is known by the developer only) is checked by giving inputs to the code. | In this testing, it is checked whether the calculator is working properly or not by giving inputs by pressing the buttons in the Calculator. |