You are on page 1of 44

AGILE TESTING &

JUNIT

Testing
Testing

is the process of checking the


functionality of the application whether it is
working as per requirements and to ensure
that at developer level, unit testing comes
into picture.
Unit testing is the testing of single entity
(class or method). Unit testing is very
essential to every software company to give a
quality product to their customers.

Agile Testing:
Agile testingis asoftware testingpractice that follows

the principles ofagile software development.


Agile testing involves all members of a crossfunctional agile team, with special expertise
contributed by testers, to ensure delivering the
business value desired by the customer at frequent
intervals, working at a sustainable pace.
Agileissometimes usedto denote any kind of
dynamic or unstructured way of working with
others, the term more commonly suggests a focused
yet rapidly iterative software process adhering to
principles

In the Agile approach, developers and testers

are seen as two sides of the same production


coin,
two
parallel
lines
that
shouldalwaysmeet and compare notes daily.

Nine principles of Agile


Testing

1st Principle
Agile teams test continuously. Its the only

way to be sure that the features implemented


during a given iteration or sprint are actually
done.
Continuous testing is the only way to ensure
continuous progress.

2nd Principle

3rd Principle

4th Principle

5th Principle

6th Principle

7th Principle

8th Principle

9th Principle

Agile Methodologies
SCRUM
XP(Extreme Programming)
DSDM (Dynamic Systems Development

Method)

Extreme Programming
The

first Extreme Programming project was


started March 6, 1996. Extreme Programming is
one of several popularAgile Processes.
Extreme Programming is successful because it
stresses customer satisfaction.
Instead of
delivering everything you could possibly want on
some date far in the future this process delivers
the software you need as you need it.
Extreme Programming empowers your developers
to confidently respond to changing customer
requirements, even late in the life cycle.

Extreme Programming emphasizes teamwork. Managers,

customers, and developers are all equal partners in a


collaborative team.
Extreme Programming implements a simple, yet effective
environment enabling teams to become highly productive.
The team self-organizes around the problem to solve it as
efficiently as possible.
Extreme Programming improves a software project in five
essential ways; communication, simplicity, feedback,
respect, and courage.
Extreme Programmers constantly communicate with their
customers and fellow programmers. They keep their
design simple and clean.
They get feedback by testing their software starting on
day one. They deliver the system to the customers as
early as possible and implement changes as suggested.

The Rules of Extreme Programming


Planning

User stories are written.


Release planning creates the release schedule.
Make frequent small releases.
The project is divided into iterations.
Iteration planning starts each iteration.
Designing

Simplicity.
Choose a system metaphor.
Use CRC cards for design sessions.
Create spike solutions to reduce risk.
No functionality is added early.
Refactor whenever and wherever possible.


Managing

Give the team a dedicated open work space.


Set a sustainable pace.
A stand up meeting starts each day.
The Project Velocity is measured.
Move people around.
Fix XP when it breaks.

Coding
The customer is always available.
Code must be written to agreed standards.
Code the unit test first.
All production code is pair programmed.
Only one pair integrates code at a time.
Integrate often.
Set up a dedicated integration computer.
Use collective ownership.

Testing
All code must have unit tests.
All code must pass all unit tests before it can be released.
When a bug is found tests are created.
Acceptance tests are run often and the score
is published.

JUNIT
JUnit is aRegression Testing Frameworkused by

developers to implement unit testing in Java and


accelerate programming speed and increase the
quality of code.
Features
JUnit test framework provides following important
features
Fixtures
Test suites
Test runners
JUnit classes

Fixtures:
Fixturesis a fixed state of a set of objects

used as a baseline for running tests. The


purpose of a test fixture is to ensure that
there is a well known and fixed environment in
which tests are run so that results are
repeatable. It includes:
setUp() method which runs before every test
invocation.
tearDown() method which runs after every
test method.

Test Suites:
Test suitemeans bundle a few unit test

cases and run it together. In JUnit, both


@RunWith and @Suite annotation are used to
run the suite test. Here is an example which
uses TestJunit1 & TestJunit2 test classes.

Test Runner
Test runneris used for executing the test

cases. Here is an example which assumes


TestJunit test class already exists.

Junit Classes
JUnit classesare important classes which is

used in writing and testing JUnits. Some of the


important classes are
Assert which contain a set of assert methods.
TestCase which contain a test case defines
the fixture to run multiple tests.
TestResult which contain methods to collect
the results of executing a test case.

Assertions
JUnit provides static methods in the Assert

class to test for certain conditions. These


assertion methods typically start with assert
and allow you to specify the error message,
the expected and the actual result.
An assertion method compares the actual
value returned by a test to the expected
value, and throws an AssertionException if the
comparison test fails.

Final procedure of using


JUNIT
Create
Create
Create
Create

class
test class
test suite class (optional)
runner class

Point to note:
Add annotation @Test before writing the test.
import org.junit.Test;
import static org.junit.Assert.assertEquals;
public class TestJunit {
String message = "Hello World";
MessageUtil messageUtil = new MessageUtil(message);
@Test
public void testPrintMessage() {
assertEquals(message,messageUtil.printMessage());
}
}

Question
Write down the Junit test cases , test suites

and run them for the class which calculates


the multiplication of two numbers. Consider all
possible boundary value test cases given the
two numbers are of range 0 to 100.
Identify the fixtures.

public class MyClassTest {


@Test(expected = IllegalArgumentException.class)
public void testExceptionIsThrown() {
MyClass tester = new MyClass();
tester.multiply(100, 5);
}
@Test
public void testMultiply() {
MyClass tester = new MyClass();
assertEquals("10 x 5 must be 50", 50, tester.multiply(10, 5));
}
}

TDD , ATDD and BDD

TDD Test Driven


Development
TDD was first evaluated in Extreme Programming
Test Driven Development (TDD)which is a process of

writing tests before writing code and make the test fail.
In this, write enough code so that test can pass and then
at last refactor the code as per you requirement and
make sure the test is passing again after the change.
Now, the main focus of TDD will be on testing the lowlevel functionality and units (for single classes and
methods) that can lead to more flexible code and easier
refactoring.
In a simple language we can say,we write these tests
to check if the code we wrote works fine.

ATDD- Acceptance Test Driven


Development
In ATDD the acceptance criteria are defined in

early in application development process and


then those criteria can be used to guide the
subsequent development work.
ATDD is a collaborative exercise that involves
product owners, business analysts, testers,
and developers.ATDD helps to ensure that all
project members understand precisely what
needs to be done and implemented.

BDD- Behavior Driven Development


BDD focuses on the behaviors of your system

exhibits than the implementation details of it.


The focus ofBDD is the language and interactions
used in the process of software development.
Behavior-driven developers use their native
language in combination with the language of
Domain Driven Design to describe the purpose
and benefit of their code.
This allows the developers to focus onDoes my
code do what its supposed to do? in
addition to Does my code work?

Tools
TDD

ATDD

BDD

Junit

Fitnesse

JBehave

cpputest

Spectacular

Lettuce

GoogleTest

Concordion

Easyb

DBFit

Thucydides

SpecFlow

You might also like