Beruflich Dokumente
Kultur Dokumente
Moamin Abughazala
Agenda
• Basic Testing
• Unit testing
• Junit with eclipse
• First test case
• Running Test
• Annotations
• Assertion
• Ignore
• Timeout
• Expected Exception
• Parametrized
• Test Suite
Basic Testing
• Software Reliability: Probability that a software system will not
cause failure under specified conditions.
• Bugs are inevitable in any complex software system.
• Industry estimates: 10-50 bugs per 1000 lines of code.
• A bug can be visible or can hide in your code until much later.
• Testing : A systematic attempt to reveal errors.
• Failed test: an error was demonstrated.
• Passed test: no error was found (for this particular situation).
Why are software tests helpful?
• Software unit tests help the developer to
verify that the logic of a piece of the
program is correct.
• Running tests automatically helps to identify
software regressions introduced by
changes in the source code. Having a high
test coverage of your code allows you to
continue developing features without
having to perform lots of manual tests
Unit testing
• Unit Test Case : is a part of code which ensures that the another
part of code (method) works as expected.(by developers)
• The percentage of code which is tested by unit tests is
typically called test coverage.
• To achieve those desired results quickly, test framework is required
.JUnit is perfect unit test framework for java programming language.
Which part of the software should be
tested?
• should every statement in your code be
tested ???!!
• You should write software tests for the
critical and complex parts of your
application.
JUnit Features
1. JUnit is an open source framework
2. Provides Annotation to identify the test
methods.
3. Provides Assertions for testing expected
results.
4. Provides Test runners for running tests.
JUnit and Eclipse
• To add JUnit to an Eclipse project, click:
• Project Properties Build Path
Libraries
Add Library... JUnit JUnit 4 Finish
• To create a test case:
• right-click a file and
choose New Test Case
• or click File New
JUnit Test Case
JUnit - Writing test class
import org.junit.*;
import static org.junit.Assert.*;
@Test
public void name() { // a test case method
...
}
}
• A method with @Test is flagged as a JUnit test case.
• All @Test methods run when JUnit runs your test class.
Running a test
• Right click it in the Eclipse Package Explorer at
left; choose:
Run As JUnit Test
• The JUnit bar will show
• Green if all tests pass,
• Red if any fail.
• The Failure Trace shows which tests
failed, if any, and why
Annotation Description
assertSame(expected, actual) fails if the values are not the same (by ==)
assertNotSame(expected, actual) fails if the values are the same (by ==)
@Test(timeout = TIMEOUT)
public void name() { ... }
23
Software testing - Definition
• Is a formal process carried out by specialized testing team
in which a software unit, several integrated software units or
entire software package are examined by running the
programs on a computer. All the associated tests are
performed according to approved test procedures on
approved test case.
24
Software testing objectives
• Direct objectives:
• To identify and reveal as many errors as possible in the tested SW.
• To bring the tested SW, after correction of the identified errors and
retesting, to an acceptable level of quality.
• To perform the required tests efficiently and effectively, within the limits
budgetary and scheduling limitation
• Indirect objectives
• To compile a record of SW errors for use in error prevention ( by
corrective & preventive actions )
25
Who Does Testing ?
1. Software Tester
2. Software Developer – Unit Testing
3. Project Lead / Manager
4. End User
It depends on the process and the associated stakeholders of the
project(s)
When to Start Testing?
• An early start to testing reduces the cost and time to rework and
produce error-free software that is delivered to the client.
• Testing can be started from the Requirements Gathering phase and
continued till the deployment of the software.
• It also depends on the development model that is being used.
• For example, in the Waterfall model, formal testing is conducted in the testing phase;
• The incremental model, testing is performed at the end of every increment/iteration and
the whole application is tested at the end.
When to Stop Testing?
• It is difficult to determine when to stop testing, as testing is a never-
ending process and no one can claim that a software is 100% tested.
• The following aspects are to be considered for stopping the testing
process : 4
• Testing Deadlines
• Completion of test case execution.
• Bug rate falls below a certain level and no high-priority bugs are identified
• Management decision
Levels of Software Testing
• Unit testing
• Integration testing
• System testing
• Acceptance testing
Unit Testing
• Unit testing is a way of testing the smallest piece of code referred to
as a unit that can be logically isolated in a system. It is mainly focused
on the functional correctness of standalone modules.
• It is the micro level of testing
• It involves testing individual modules or units to make sure they're
working properly
• Unit testing
1. Unit tests improve the quality of your code
2. Find Software Bugs Early
3. Reduces Testing Costs
• What are the other Benefits of Unit Testing??!
Integration testing
• After Unit testing we have Integration testing
• this level tell how units work together
• Individual module are combined and tested as a group, it's one thing
if units walk well on their own but how do they perform together when
combined
• Integration testing :
1. helps you determine that and ensure your application runs efficiently
2. Identifies interface issues between modules
The Need for Integration testing
• A module/unit is usually designed by an individual software developer
whose techniques and programming logic differs from that of other
programmers
• Often at the time of module development, user requirements change
and these new requirements may not be unit tested.
• Issues like data formatting, hardware interfaces, and third-party
service interfaces are sometimes missed during unit testing
System Testing
• All components of the software are tested as whole in order to ensure
that overall product meets the requirements which are specified.
• It is performed on the entire system in the context of either functional
requirement specifications (FRS) or system requirement specification
(SRS), or both. System testing tests not only the design, but also the
behavior and even the believed expectations of the customer.
• System Testing :
• it verifies technical, functional, and business requirements of the software or an
application
• It is usually done by testing team and it includes a combination of automation
testing as well as manual testing techniques.
Acceptance testing
• the final level of testing is acceptance testing or basically we call it
UAT (User Acceptance testing)
• It determines whether or not the software product is ready to be
released to market
• the functionality or functional requirements met or performance
requirement met or not
• UAT is the final say as to whether the application is ready for the use
in real life or not
Software Testing II
Software testing Strategies
• Incremental testing
• Bottom-Up Testing
• Top-Down Testing
45
Bottom-up Testing
• The order of testing is reversed: the lowest level module are tested
first with the main module will be tested last.
48
Software testing classification - code visible
level
• Black box ( functionality ) testing:
• Identifies bugs only according to SW malfunctioning as
they are revealed in its erroneous output.
• Incases that outputs are found to be correct, black box
testing disregarded the internal path of calculations and
processing performed.
• White box ( structural ) testing:
• Examines internal calculation paths in order to identify
bugs.
49
White box and black box testing for the various
classes of tests
50
White Box Testing
• White box testing is testing of a software solution's internal structure,
design, and coding.
• the code is visible. It focuses primarily on verifying the flow of inputs
and outputs through the application, improving design and usability,
strengthening security
• White box testing is also known as Clear Box testing, Open Box testing,
Structural testing, Transparent Box testing, Code-Based testing, and
Glass Box testing.
• It is usually performed by developers.
51
What do you verify in White Box Testing?
• White box testing involves
1. Internal security holes
2. poorly structured paths in the coding processes
3. The flow of specific inputs through the code
4. Expected output
5. The functionality of conditional loops
6. Testing of each statement, object, and function on an individual basis
• Dis.
• White box testing is too much time consuming when it comes to large-scale programming
applications.
• White box testing is much expensive and complex.
• It can lead to production error because it is not detailed by the developers.
• White box testing needs professional programmers
Black box testing
• It is a testing technique in which functionality of the Application Under Test
(AUT) is tested without looking at the internal code structure, implementation
details and knowledge of internal paths of the software.
• This type of testing is based entirely on software requirements and
specifications. In Black Box Testing we just focus on inputs and output of the
software system without bothering about internal knowledge of the software
program.
• The testing can be done at Acceptance & System levels of software development
61
Types of Black Box Testing
• Functional testing - This black box testing type is related to the
functional requirements of a system;
• Non-functional testing - This type of black box testing is not related to
testing of specific functionality, but non-functional requirements such
as performance, scalability, usability.
Advantages and Dis. of black box testing
• Advantages
• Allows carrying out the majority of testing classes, such as load tests and availability tests
• Requires fewer resources than those required for white box testing
• Disadvantages
• Absence of control of line coverage.
• Impossibility of testing the quality of coding and its strict adherence to the coding standards.
63