4. “
Software Testing
“If debugging is the process of removing software bugs,
then programming must be the process of putting them in”
(Dijkstra )
“It's not a bug - it's an undocumented feature.”
(Anonymous )
5. ● A primary purpose of testing is to detect software failures so that defects
may be discovered and corrected.
● Software testing can also provide an objective, independent view of the
software to allow the business to appreciate and understand the risks of
implementation.
Software Testing
6. ● Writing (good) tests is expensive and it’s not easy because of:
○ Deadlines
○ Resources
○ Business Area
○ Knowledge (technologies, domain..)
Software Testing
7. ..So, why is it useful to write test code?
Software Testing
8. ● Benefits are:
○ Requirement
○ Software usability
○ System responds correctly to all kinds of inputs and performs its
functions within an acceptable time
○ Regression test
Software Testing
13. ● Testing models are:
○ Traditional waterfall.
○ Agile or Extreme development, unit tests are written first
■ Test-driven development
○ Top-down or bottom-up.
Software Testing
14. ● Mocking is the creation of fake objects which helps the unit testing process.
Software Testing
15. ● You should not test:
○ Other framework libraries
○ The database
○ Really trivial code
○ Code that has non deterministic results
○ Code that deals only with UI
Software Testing - Guidelines
16. ● You should test:
○ Business logic
○ Core code that is accessed by a lot of other modules
○ Code that changes by multiple different developers (often to
accommodate new requirements)
Software Testing - Guidelines
18. ● It’s a unit testing framework for the Java programming language
http://junit.org/junit4/
● A research survey performed in 2013 across 10,000 Java projects hosted on
GitHub found that JUnit was the most commonly included external library.
Each library was used by 30.7% of project
● Current version: 5
JUnit
19. Some features are:
● Most Java IDEs (i.e. Eclipse, IntelliJ IDEA, NetBeans) have explicit support for
JUnit
● Automated test
● Assertion based
● Test case = a test class composed by one or more test methods
JUnit
20. ● Each single test method:
○ has the purpose of verifying the operation of our code in a specific case
(with reference to a specific dataset)
○ contains an invocation of our software method
○ has the purpose of comparing results; this comparison is realized by an
assertion
JUnit
21. @BeforeClass
public static void setUpClass() throws Exception {
// Code executed before the first test method
}
@Before
public void setUp() throws Exception {
// Code executed before each test
}
@Test
public void testOneThing() {
// Code that tests one thing
}
JUnit: some annotations
22. @Test
public void testAnotherThing() {
// Code that tests another thing
}
@After
public void tearDown() throws Exception {
// Code executed after each test
}
@AfterClass
public static void tearDownClass() throws Exception {
// Code executed after the last test method
}
JUnit: some annotations
33. ● SoapUI is an open-source web service testing application for service-oriented
architectures (SOA) and representational state transfers (REST)
● ..web service inspection, invoking, development, simulation and mocking,
functional testing, load and compliance testing.
● Commercial version vs Free version
SoapUI
37. ● Code coverage is a measure used to describe the degree to which the source
code of a program is executed when a particular test suite runs
● Fault injection (stress test) may be necessary to ensure that all conditions
and branches of exception handling code have adequate coverage during
testing.
Code coverage
38. ● Many different metrics can be used to calculate code coverage:
○ Function coverage - Has each function in the program been called?
○ Statement coverage - Has each statement in the program been executed?
○ Branch coverage - Has each branch of each control structure been executed?
○ Condition coverage - Has each Boolean sub-expression evaluated both to true and false?
○ Loop coverage - Has every possible loop been executed?
○ Path coverage – Has every possible route through a given part of the code been executed?
Code coverage
39. ● Full path coverage is usually impractical or impossible:
○ Any module with a succession of n decisions in it can have up to 2^n paths
○ Loop constructs can result in an infinite number of paths
○ Many paths may also be infeasible, in that there is no input to the program under
test
Code coverage
40. ● EclEmma is a free Java code coverage tool, it brings code coverage analysis
directly into the Eclipse workbench
● The Eclipse integration has its focus on supporting the individual developer in
an highly interactive way
EclEmma
41. ● Most important analysis features are:
○ Coverage overview: lists coverage summaries for your Java projects, allowing
drill-down to method level.
○ Source highlighting: The result of a coverage session is also directly visible in the
Java source editors.
○ Different counters, Multiple coverage sessions, Merge Sessions
EclEmma
43. ▷ Heisenbug: “A computer bug that disappears or alters its characteristics
when an attempt is made to study it.”
▷ Higgs-Bugson: “A hypothetical bug predicted to exist based on a small
number of possibly related event”
Bug Types
44. ▷ Loch Ness Monster Bug: “I've started searching Loch Ness Monster bug for
anything not reproducible or only sighted by one person.”
▷ Hindenbug: “A catastrophic data destroying bug”.
● Also related to Counterbug (a bug you present when presented with a bug caused by the
person presenting the bug) and Bloombug (a bug that accidentally generates money).
Bug Types