This document discusses software testing fundamentals and types of testing. It explains that quality assurance teams are responsible for certifying that product features and functionalities match what is promised. Testing is important to deliver reliable, quality products that function as intended. The types of testing discussed are manual testing and automation testing. Automation testing is presented as more important because it builds safety, allows for reuse and refactoring with confidence, and reduces bugs. The document also discusses test-driven development, how to structure unit tests, and libraries that can be used for writing unit tests like JUnit.
4. Who is responsible for making sure the features
and functionalities are as mentioned
Showroom owner
Showroom executive
Manufacturing plant owner
Specific car manufacturing unit manager
Quality Assurance team - Responsible for certifying the functionalities
5. Why Testing is important ?
To deliver reliable
product
Product delivers what is
promised
It does not malfunction
To deliver a quality
product
Product should be
durable
Product should tolerate
few error conditions
8. Rectangle Class
public class Rectangle {
public double getArea(double length, double width){
validateForZeroLength(length, width);
return length * width;
}
private void validateForZeroLength(double length, double width) {
if (length <= 0.0 || width <= 0.0) {
throw new RuntimeException("Invalid values are received for either length or width");
}
}
}
public class ManualTestScenarios {
public static void main(String[] args) {
// test the area
// scenarios
// pass different values (10,20) , (100,200.5) , (1,2)
// test for zero length
Rectangle rectangle = new Rectangle();
double area = rectangle.getArea(300.5, 200.9);
System.out.println("Area of rectangle having length:"+300.5+" and "+200.9+" width is "+area);
area = rectangle.getArea(1, 1);
System.out.println("Area of rectangle having length:"+1+" and "+1+" width is "+area);
try {
area = rectangle.getArea(0, 0);
}catch(RuntimeException runtimeException ){
System.out.println(runtimeException.getMessage());
}
}
}
9. Disadvantage of manual tests
Time consuming
and Expensive
Routine and Boring
Must be repeated
by all Stakeholders
10. Automation tests for Rectangle class
class RectangleTest {
@Test
void getAreaForWholeNumberLengths() {
Rectangle rectangle = new Rectangle();
double area = rectangle.getArea(10, 20);
assertEquals(200.0, area);
area = rectangle.getArea(1, 2);
assertEquals(2, area);
}
@Test
void getAreaForDecimalNumberLengths() {
Rectangle rectangle = new Rectangle();
double area = rectangle.getArea(10.5, 20.9);
assertEquals(219.45, area);
area = rectangle.getArea(100.3, 2456.7);
assertEquals(246407.01, area, 0.001);
}
@Test
void getAreaForZeroWidthRectangle() {
Rectangle rectangle = new Rectangle();
assertThrows(RuntimeException.class, ()-> rectangle.getArea(10.5, 0.0));
}
}
11. Why Automation tests are important ?
Builds a safety net and
defend against other
programmers
Reusable and
Repeatable
Reduce Bugs in New
features as well as in
existing features
Allow refactoring with
confidence
Improve Design
Documents the
features
Reduce the need of the
IDE debugger
15. Criteria for
good Unit
tests
Small and Simple:
• Easy to quickly comprehend
Runs Fast
Express intent and not the implementation details
Runs independently and in isolation
Runs in Parallel
Repeatable
17. Write few unit
tests for
Calculator
functionalities
Structure of a typical test
Given
preconditions
When
Calling a function
Then
Verify the result
Test Result
Success
Failed
Error
19. Test Driven Development
Test, Code, Refactor
TDD
Methodology to write tests first
Focus on minimalistic code design
Speculative generality is avoided
Evolutionary design
20. Write a test for the next bit of
functionality you want to add.
Write the functional code until the
test passes.
Refactor both new and old code to
make it well structured.
Test- Code – Test- Refactor-Test
Add a test
Does it pass ?
Add enough
code to pass
the test
Refactor/Add
features
No
Run the tests
Yes