SlideShare a Scribd company logo
© 2015 Return on Intelligence, Inc. Confidential 1
Traning for beginers in UT development
Designed by LibreOffice, Kubuntu 14.04, A.Tylevich, 2016
Unit Tests ? It is very simple and easy!
© 2015 Return on Intelligence, Inc. Confidential 2
About training
This is introduction.
Tries to explain why all this is necessary.
A little of code, more philosophy and history
Why ?
For whom ?
Designed by LibreOffice, Kubuntu 14.04
© 2015 Return on Intelligence, Inc. Confidential 3
Content
Historical reference
What are Unit Tests ?
UT - what for they are necessary (philosophy)
What is the Unit and what can be the Unit
Approaches in UT
Without frameworks (stub classes)
Frameworks (examples, annotations)
UT frameworks
Junit 3, 4 (Asserts …)
TestNG
Mock frameworks
JMock
EasyMock
Mockito
EJB Mock Container
Additional frameworks
Equals Verifier
Addition of dependences in pom.xml
Code Coverage
Cobertura
Covering examples
… tools
Automation tests
QTP, Selenium
FitNesse
Links to literature and sources
Designed by LibreOffice, Kubuntu 14.04
© 2015 Return on Intelligence, Inc. Confidential 4
One of the first
attempts to
create a
programming
language, from
1943 to 1945
1940 1980 1990
In the early of 1950s
the quantity of the
developed software
increased, and
programs became
very big
1950
FORTRAN(1954)
ALGOL(1960)
Mashine
languages
Pascal(1970),
C(1972),
SQL(1978)
C++(1980),
Ada(1983),
Perl(1987)
PHP(1995),
Java(1995),
JavaScript(1995)
Some important
languages were
developed:
Python (1991),
Ruby (1993),
Delphi (1995), ...
Improvement of
the paradigms
defined in the
previous
decades
NewParadigms
and…
Historical reference
Programming languages
Designed by LibreOffice, Kubuntu 14.04
1960
New languages
appear:
Smalltalk (1972)
1970
© 2015 Return on Intelligence, Inc. Confidential 5
Historical reference
Designed by LibreOffice, Kubuntu 14.04
Testing
1980
Correctness->
searchforissues
Preventionof
mistakes
Designand
supportoftests
Early 1990s, the testing
includes planning, design,
support and implementation
of tests.
The testing starts providing
quality of the software.
1980s, a concept of the
prevention of defects appears.
Tests - method of the
prevention of issues.
Appears methodology of testing
on all cycle of development.
Exhaustive
testing
Early 1970s, testing was
presented as "activities for
confirmation of correctness of
work of the software"
From confirmations to search for
issues
1970 19901960
© 2015 Return on Intelligence, Inc. Confidential 6
Framework SUnit appears for Smalltalk language in 1998 .
Designed by LibreOffice, Kubuntu 14.04
Historical reference
Testing
SUnit represented structure and functionality to xUnit.
CppUnit - a framework for C ++
DUnit - the tool for the environment of development of Delphi
JUnit - library for Java
NUnit - environment a unit testing for .NET
phpUnit - library for PHP
vbUnit - Visual Basic
JsUnit (Jasmine) - JavaScript
© 2015 Return on Intelligence, Inc. Confidential 7
What are Unit Tests
Unit Testing is a software testing process by which individual module of
source code ... are tested to determine whether they are fit for use.
What is the process?
What is module ?
Process — implementation, writing and run of Unit Tests
Module — atomic part of a code
Designed by LibreOffice, Kubuntu 14.04
Unit testing, wikipedia
© 2015 Return on Intelligence, Inc. Confidential 8
UT - what for they are necessary
In the 1990s testing passed to ensuring the quality covering all cycle of development
You constantly are engaged in testing
(This is integration testing: "Test" buttons or class with name TestServer)
Some customers demand a very high level of testing
You need to understand how code works
You need to write a part of code, but you have no opportunity to test it in actual
environment and you exactly know what data will come to methods
It isn't necessary to write unit tests, if
You do the simple site of 3-5 html-pages with one form of sending the e-mail
You are developed a simple flash games or banners
You do the project for an exhibition
You always write a code without mistakes, you have an ideal brain and gift of
anticipation. Your code is so cool that it changes itself according to customer
requirements. Periodically the code explains to the customer that his requirements
don't need to be realized
Designed by LibreOffice, Kubuntu 14.04
Philosophy
© 2015 Return on Intelligence, Inc. Confidential 9
What is the Unit
Program
Module
Class
Method
That you will think up
Unit -
small self-sufficient part of a code realizing some behavior.
Designed by LibreOffice, Kubuntu 14.04
What can be Unit
© 2015 Return on Intelligence, Inc. Confidential 10
Approaches in UT
UT
simple atomic testing
TDD
(Test-Driven Development)
Development through testing.
Designed by LibreOffice, Kubuntu 14.04
UT -> TDD -> BDD -> DDT
© 2015 Return on Intelligence, Inc. Confidential 11
Approaches in UT
BDD
(Behavior Driven Development)
BDD is further evolution of ideas of TDD.
DDT
(Data-Driven Testing)
Methodology of the testing operated by data.
Designed by LibreOffice, Kubuntu 14.04
UT -> TDD -> BDD -> DDT
© 2015 Return on Intelligence, Inc. Confidential 12
Without frameworks
RDP ?
RDP !
Designed by LibreOffice, Kubuntu 14.04
Or how it was earlier ?
Frameworks
Or how it is now ?
RDP.
RDP.
© 2015 Return on Intelligence, Inc. Confidential 13
Framework JUnit 3 JUnit 4
Java version Java 1.4 Java 1.5
Extends TestCase -
Overrides setUp & tearDown annotations
Annotations -
@Before
@After
@Test
@Ignore
Repeated RepeatedTest @Repeat( times = xxx )
UT Frameworks
JUnit 3, 4 (Asserts…)
Designed by LibreOffice, Kubuntu 14.04
© 2015 Return on Intelligence, Inc. Confidential 14
UT Frameworks
Designed by LibreOffice, Kubuntu 14.04
TestNG
Framework JUnit 4 TestNG
Test annotation @Test @Test
Start before the suit – @BeforeSuite
Start after the suit – @AfterSuite
Start before test – @BeforeTest
Start after test – @AfterTest
Start before test from group – @BeforeGroups
Start after test from group – @AfterGroups
Start before a class @BeforeClass @BeforeClass
Start after a class @AfterClass @AfterClass
Start before each test method @Before @BeforeMethod
Start after each test method @After @AfterMethod
To ignore the test @Ignore @Test(enable=false)
To expect an exception @Test (expected = Exception.class) @Test (expectedExceptions = Exception.class)
Timeout @Test (timeout = 1000) @Test (timeout = 1000)
© 2015 Return on Intelligence, Inc. Confidential 15
UT Frameworks
Designed by LibreOffice, Kubuntu 14.04
Addition of dependences into pom.xml
JUnit 3 JUnit 4 TestNG
<dependencies>
...
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
<dependencies>
...
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
</dependencies>
<dependencies>
...
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.9.10</version>
<scope>test</scope>
</dependency>
</dependencies>
© 2015 Return on Intelligence, Inc. Confidential 16
Mock frameworks
Designed by LibreOffice, Kubuntu 14.04
And additional frameworks
JMock
Mockito
EasyMock
EJB Mock Container
Equals Verifier
Framework JMock Mockito
Type Proxy-based Proxy-based
Stubbing Yes Yes
Default return values 0, empty String, false, empty array, null 0, empty String, false, empty array, null
Instances are Strict Non-strict
Declarative No Yes
Interface additional efforts From box
Abstract class additional efforts ?
Class additional efforts From box
© 2015 Return on Intelligence, Inc. Confidential 17
Mock frameworks
Designed by LibreOffice, Kubuntu 14.04
Addition of dependences into pom.xml
JMock Mockito Equals Verifier
<dependencies>
...
<dependency>
<groupId>org.jmock</groupId>
<artifactId>jmock</artifactId>
<version>2.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
<dependencies>
...
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-all</artifactId>
<version>1.10.19</version>
<scope>test</scope>
</dependency>
</dependencies>
<dependencies>
…
<dependency>
<groupId>nl.jqno.equalsverifier</groupId>
<artifactId>equalsverifier</artifactId>
<version>1.7.7</version>
<scope>test</scope>
</dependency>
</dependencies>
© 2015 Return on Intelligence, Inc. Confidential 18
Code Coverage
Designed by LibreOffice, Kubuntu 14.04
Cobertura
if (x == 0) {
System.out.println("X is zero");
} else {
System.out.println("X is invalid");
}
© 2015 Return on Intelligence, Inc. Confidential 19
Code Coverage
Designed by LibreOffice, Kubuntu 14.04
Addition of Cobertura dependences into pom.xml
Dependency section Build section Reporting section
<dependencies>
...
<dependency>
<groupId>
net.sourceforge.cobertura
</groupId>
<artifactId>cobertura</artifactId>
<version>2.1.1</version>
</dependency>
</dependencies>
<build>
<plugins>
...
<plugin>
<groupId>
org.codehaus.mojo
</groupId>
<artifactId>
cobertura-maven-plugin
</artifactId>
<version>2.6</version>
<configuration>
<check>
<...Rate> ...</...Rate>
</check>
<formats>
<format>html</format>
</formats>
<instrumentation>
<excludes>
<exclude> ... /*.class</exclude>
</excludes>
</instrumentation>
</configuration>
</plugin>
</plugins>
</build>
<reporting>
<plugins>
...
<plugin>
<groupId>
org.codehaus.mojo
</groupId>
<artifactId>
cobertura-maven-
plugin
</artifactId>
<version>2.6</version>
<configuration>
<formats>
<format>html</format>
<format>xml</format>
</formats>
</configuration>
</plugin>
</plugins>
</reporting>
© 2015 Return on Intelligence, Inc. Confidential 20
Automation tests
Designed by LibreOffice, Kubuntu 14.04
QTP, Selenium
QTP Selenium
Commercial tool Open source tool
Tests can only be developed in QTP IDE Wide range of IDEs like Visual Studio,
Eclipse, Netbeans
Oly VB script Supports JAVA, .NET, Ruby, Perl, PHP, and
many other
User friendly and scripts are developed quickly Script requires more time to develop and
high skills
Latest version of HP ALM supports code that was
developed 5 years back
With new release of API the Test Scripts
need to be updated
© 2015 Return on Intelligence, Inc. Confidential 21
Automation tests
Designed by LibreOffice, Kubuntu 14.04
FitNesse
© 2015 Return on Intelligence, Inc. Confidential 22
Example
Designed by LibreOffice, Kubuntu 14.04
Why UT are necessary
© 2015 Return on Intelligence, Inc. Confidential 23
Questions
Designed by LibreOffice, Kubuntu 14.04
© 2015 Return on Intelligence, Inc. Confidential 24
Links
Designed by LibreOffice, Kubuntu 14.04
History of programming languages
https://en.wikipedia.org/wiki/History_of_programming_languages
TDD
https://en.wikipedia.org/wiki/Test-driven_development
BDD
https://en.wikipedia.org/wiki/Behavior-driven_development
xUnit
https://en.wikipedia.org/wiki/XUnit
JUnit
http://junit.org/cookbook.html
Open Source Testing Tools in Java
http://java-source.net/open-source/testing-tools
Cobertura
https://github.com/cobertura/cobertura/wiki/Roadmap
http://cobertura.github.io/cobertura/
eCobertura (Eclipce plugin)
http://ecobertura.johoop.de/
EqualsVerifier
http://www.jqno.nl/equalsverifier/
© 2015 Return on Intelligence, Inc. Confidential 25
Links to webinars
Designed by LibreOffice, Kubuntu 14.04
Вебинар "Introduction to Automation Testing"
http://www.returnonintelligence.ru/webinars/introduction-to-automation-testing
Вебинар "Code Coverage“
http://www.returnonintelligence.ru/webinars/code-coverage
Вебинар "Testing Your Code“ (TDD)
http://www.returnonintelligence.ru/webinars/testingyourcode
Вебинар "Эволюция к Behavior Driven Development на примере популярного фреймворка
JBehave"
http://www.returnonintelligence.ru/webinars/bdd

More Related Content

What's hot (19)

DOC
Questions of java
Waseem Wasi
 
PDF
Unit testing (eng)
Anatoliy Okhotnikov
 
PPTX
DevLabs Alliance Top 50 Selenium Interview Questions for SDET
DevLabs Alliance
 
PPTX
Top 20 software testing interview questions for sdet
DevLabs Alliance
 
PDF
Php unit (eng)
Anatoliy Okhotnikov
 
PDF
Being a professional software tester
Anton Keks
 
ODP
Debugging
Olivier Teytaud
 
PDF
Software Engineering - RS3
AtakanAral
 
PPT
RPG Program for Unit Testing RPG
Greg.Helton
 
PPTX
Type Annotations in Java 8
FinLingua, Inc.
 
PDF
37 Java Interview Questions
Arc & Codementor
 
PDF
201 core java interview questions oo ps interview questions - javatpoint
ravi tyagi
 
PDF
Cursus phpunit
Nick Belhomme
 
PPT
Understanding Annotations in Java
Ecommerce Solution Provider SysIQ
 
PDF
Spring IO 2015 Spock Workshop
Fernando Redondo Ramírez
 
PDF
Agile Days Twin Cities 2011
Brian Repko
 
PPT
Stopping the Rot - Putting Legacy C++ Under Test
Seb Rose
 
PPTX
Introduction about Python by JanBask Training
JanBask Training
 
PPTX
Using Entity Framework's New POCO Features: Part 1, by Julie Lerman
Julie Lerman
 
Questions of java
Waseem Wasi
 
Unit testing (eng)
Anatoliy Okhotnikov
 
DevLabs Alliance Top 50 Selenium Interview Questions for SDET
DevLabs Alliance
 
Top 20 software testing interview questions for sdet
DevLabs Alliance
 
Php unit (eng)
Anatoliy Okhotnikov
 
Being a professional software tester
Anton Keks
 
Debugging
Olivier Teytaud
 
Software Engineering - RS3
AtakanAral
 
RPG Program for Unit Testing RPG
Greg.Helton
 
Type Annotations in Java 8
FinLingua, Inc.
 
37 Java Interview Questions
Arc & Codementor
 
201 core java interview questions oo ps interview questions - javatpoint
ravi tyagi
 
Cursus phpunit
Nick Belhomme
 
Understanding Annotations in Java
Ecommerce Solution Provider SysIQ
 
Spring IO 2015 Spock Workshop
Fernando Redondo Ramírez
 
Agile Days Twin Cities 2011
Brian Repko
 
Stopping the Rot - Putting Legacy C++ Under Test
Seb Rose
 
Introduction about Python by JanBask Training
JanBask Training
 
Using Entity Framework's New POCO Features: Part 1, by Julie Lerman
Julie Lerman
 

Similar to Unit Tests? It is Very Simple and Easy! (20)

PDF
junit-160729073220 eclipse software testing.pdf
KomalSinghGill
 
PPSX
Junit
FAROOK Samath
 
PDF
JUnit Testing Framework A Complete Guide.pdf
flufftailshop
 
PDF
JUnit Testing Framework A Complete Guide.pdf
flufftailshop
 
PPTX
Skillwise Unit Testing
Skillwise Group
 
PDF
Game Programming 06 - Automated Testing
Nick Pruehs
 
PDF
JUnit with_mocking
Zeeshan Khan
 
PPTX
The Test way
Mikhail Grinfeld
 
PDF
L08 Unit Testing
Ólafur Andri Ragnarsson
 
PDF
Introduction To UnitTesting & JUnit
Mindfire Solutions
 
PPTX
Automation testing & Unit testing
Kapil Rajpurohit
 
PDF
Introduction to test automation in java and php
Tho Q Luong Luong
 
PPTX
Test-Driven Development
John Blum
 
PPT
Automated testing overview
Alex Pop
 
PPTX
JUnit- A Unit Testing Framework
Onkar Deshpande
 
PPTX
Unit tests & TDD
Dror Helper
 
PPTX
8-testing.pptx
ssuserd0fdaa
 
PPTX
Unit Testing in Java
Ahmed M. Gomaa
 
PDF
Junit tutorial
Main Uddin Patowary
 
junit-160729073220 eclipse software testing.pdf
KomalSinghGill
 
JUnit Testing Framework A Complete Guide.pdf
flufftailshop
 
JUnit Testing Framework A Complete Guide.pdf
flufftailshop
 
Skillwise Unit Testing
Skillwise Group
 
Game Programming 06 - Automated Testing
Nick Pruehs
 
JUnit with_mocking
Zeeshan Khan
 
The Test way
Mikhail Grinfeld
 
L08 Unit Testing
Ólafur Andri Ragnarsson
 
Introduction To UnitTesting & JUnit
Mindfire Solutions
 
Automation testing & Unit testing
Kapil Rajpurohit
 
Introduction to test automation in java and php
Tho Q Luong Luong
 
Test-Driven Development
John Blum
 
Automated testing overview
Alex Pop
 
JUnit- A Unit Testing Framework
Onkar Deshpande
 
Unit tests & TDD
Dror Helper
 
8-testing.pptx
ssuserd0fdaa
 
Unit Testing in Java
Ahmed M. Gomaa
 
Junit tutorial
Main Uddin Patowary
 
Ad

More from Return on Intelligence (20)

PPTX
Clean Code Approach
Return on Intelligence
 
PPTX
Code Coverage
Return on Intelligence
 
PPTX
Effective Communication in english
Return on Intelligence
 
PPTX
Anti-patterns
Return on Intelligence
 
PPTX
Conflicts Resolving
Return on Intelligence
 
PPTX
Database versioning with liquibase
Return on Intelligence
 
PPTX
Effective Feedback
Return on Intelligence
 
PPTX
English for Negotiations 2016
Return on Intelligence
 
PPTX
Lean Software Development
Return on Intelligence
 
PPTX
Quick Start to AngularJS
Return on Intelligence
 
PPTX
Introduction to Backbone.js & Marionette.js
Return on Intelligence
 
PPTX
Types of testing and their classification
Return on Intelligence
 
PPTX
Introduction to EJB
Return on Intelligence
 
PPTX
Enterprise Service Bus
Return on Intelligence
 
PPTX
Apache cassandra - future without boundaries (part3)
Return on Intelligence
 
PPTX
Apache cassandra - future without boundaries (part2)
Return on Intelligence
 
PPTX
Apache cassandra - future without boundaries (part1)
Return on Intelligence
 
PPTX
Career development in exigen services
Return on Intelligence
 
PPTX
Introduction to selenium web driver
Return on Intelligence
 
PPTX
Enterprise service bus part 2
Return on Intelligence
 
Clean Code Approach
Return on Intelligence
 
Code Coverage
Return on Intelligence
 
Effective Communication in english
Return on Intelligence
 
Anti-patterns
Return on Intelligence
 
Conflicts Resolving
Return on Intelligence
 
Database versioning with liquibase
Return on Intelligence
 
Effective Feedback
Return on Intelligence
 
English for Negotiations 2016
Return on Intelligence
 
Lean Software Development
Return on Intelligence
 
Quick Start to AngularJS
Return on Intelligence
 
Introduction to Backbone.js & Marionette.js
Return on Intelligence
 
Types of testing and their classification
Return on Intelligence
 
Introduction to EJB
Return on Intelligence
 
Enterprise Service Bus
Return on Intelligence
 
Apache cassandra - future without boundaries (part3)
Return on Intelligence
 
Apache cassandra - future without boundaries (part2)
Return on Intelligence
 
Apache cassandra - future without boundaries (part1)
Return on Intelligence
 
Career development in exigen services
Return on Intelligence
 
Introduction to selenium web driver
Return on Intelligence
 
Enterprise service bus part 2
Return on Intelligence
 
Ad

Recently uploaded (20)

PDF
Open Chain Q2 Steering Committee Meeting - 2025-06-25
Shane Coughlan
 
PPTX
Homogeneity of Variance Test Options IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
PPTX
Get Started with Maestro: Agent, Robot, and Human in Action – Session 5 of 5
klpathrudu
 
PDF
AI + DevOps = Smart Automation with devseccops.ai.pdf
Devseccops.ai
 
PDF
UITP Summit Meep Pitch may 2025 MaaS Rebooted
campoamor1
 
PDF
[Solution] Why Choose the VeryPDF DRM Protector Custom-Built Solution for You...
Lingwen1998
 
PDF
AI Prompts Cheat Code prompt engineering
Avijit Kumar Roy
 
PDF
SAP Firmaya İade ABAB Kodları - ABAB ile yazılmıl hazır kod örneği
Salih Küçük
 
PPTX
AEM User Group: India Chapter Kickoff Meeting
jennaf3
 
PPTX
Comprehensive Risk Assessment Module for Smarter Risk Management
EHA Soft Solutions
 
PDF
Everything you need to know about pricing & licensing Microsoft 365 Copilot f...
Q-Advise
 
PDF
MiniTool Power Data Recovery 8.8 With Crack New Latest 2025
bashirkhan333g
 
PPTX
In From the Cold: Open Source as Part of Mainstream Software Asset Management
Shane Coughlan
 
PPTX
Build a Custom Agent for Agentic Testing.pptx
klpathrudu
 
PDF
Add Background Images to Charts in IBM SPSS Statistics Version 31.pdf
Version 1 Analytics
 
PDF
Wondershare PDFelement Pro Crack for MacOS New Version Latest 2025
bashirkhan333g
 
PDF
Salesforce Experience Cloud Consultant.pdf
VALiNTRY360
 
PDF
How to Hire AI Developers_ Step-by-Step Guide in 2025.pdf
DianApps Technologies
 
PPTX
Home Care Tools: Benefits, features and more
Third Rock Techkno
 
PDF
Download Canva Pro 2025 PC Crack Full Latest Version
bashirkhan333g
 
Open Chain Q2 Steering Committee Meeting - 2025-06-25
Shane Coughlan
 
Homogeneity of Variance Test Options IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
Get Started with Maestro: Agent, Robot, and Human in Action – Session 5 of 5
klpathrudu
 
AI + DevOps = Smart Automation with devseccops.ai.pdf
Devseccops.ai
 
UITP Summit Meep Pitch may 2025 MaaS Rebooted
campoamor1
 
[Solution] Why Choose the VeryPDF DRM Protector Custom-Built Solution for You...
Lingwen1998
 
AI Prompts Cheat Code prompt engineering
Avijit Kumar Roy
 
SAP Firmaya İade ABAB Kodları - ABAB ile yazılmıl hazır kod örneği
Salih Küçük
 
AEM User Group: India Chapter Kickoff Meeting
jennaf3
 
Comprehensive Risk Assessment Module for Smarter Risk Management
EHA Soft Solutions
 
Everything you need to know about pricing & licensing Microsoft 365 Copilot f...
Q-Advise
 
MiniTool Power Data Recovery 8.8 With Crack New Latest 2025
bashirkhan333g
 
In From the Cold: Open Source as Part of Mainstream Software Asset Management
Shane Coughlan
 
Build a Custom Agent for Agentic Testing.pptx
klpathrudu
 
Add Background Images to Charts in IBM SPSS Statistics Version 31.pdf
Version 1 Analytics
 
Wondershare PDFelement Pro Crack for MacOS New Version Latest 2025
bashirkhan333g
 
Salesforce Experience Cloud Consultant.pdf
VALiNTRY360
 
How to Hire AI Developers_ Step-by-Step Guide in 2025.pdf
DianApps Technologies
 
Home Care Tools: Benefits, features and more
Third Rock Techkno
 
Download Canva Pro 2025 PC Crack Full Latest Version
bashirkhan333g
 

Unit Tests? It is Very Simple and Easy!

  • 1. © 2015 Return on Intelligence, Inc. Confidential 1 Traning for beginers in UT development Designed by LibreOffice, Kubuntu 14.04, A.Tylevich, 2016 Unit Tests ? It is very simple and easy!
  • 2. © 2015 Return on Intelligence, Inc. Confidential 2 About training This is introduction. Tries to explain why all this is necessary. A little of code, more philosophy and history Why ? For whom ? Designed by LibreOffice, Kubuntu 14.04
  • 3. © 2015 Return on Intelligence, Inc. Confidential 3 Content Historical reference What are Unit Tests ? UT - what for they are necessary (philosophy) What is the Unit and what can be the Unit Approaches in UT Without frameworks (stub classes) Frameworks (examples, annotations) UT frameworks Junit 3, 4 (Asserts …) TestNG Mock frameworks JMock EasyMock Mockito EJB Mock Container Additional frameworks Equals Verifier Addition of dependences in pom.xml Code Coverage Cobertura Covering examples … tools Automation tests QTP, Selenium FitNesse Links to literature and sources Designed by LibreOffice, Kubuntu 14.04
  • 4. © 2015 Return on Intelligence, Inc. Confidential 4 One of the first attempts to create a programming language, from 1943 to 1945 1940 1980 1990 In the early of 1950s the quantity of the developed software increased, and programs became very big 1950 FORTRAN(1954) ALGOL(1960) Mashine languages Pascal(1970), C(1972), SQL(1978) C++(1980), Ada(1983), Perl(1987) PHP(1995), Java(1995), JavaScript(1995) Some important languages were developed: Python (1991), Ruby (1993), Delphi (1995), ... Improvement of the paradigms defined in the previous decades NewParadigms and… Historical reference Programming languages Designed by LibreOffice, Kubuntu 14.04 1960 New languages appear: Smalltalk (1972) 1970
  • 5. © 2015 Return on Intelligence, Inc. Confidential 5 Historical reference Designed by LibreOffice, Kubuntu 14.04 Testing 1980 Correctness-> searchforissues Preventionof mistakes Designand supportoftests Early 1990s, the testing includes planning, design, support and implementation of tests. The testing starts providing quality of the software. 1980s, a concept of the prevention of defects appears. Tests - method of the prevention of issues. Appears methodology of testing on all cycle of development. Exhaustive testing Early 1970s, testing was presented as "activities for confirmation of correctness of work of the software" From confirmations to search for issues 1970 19901960
  • 6. © 2015 Return on Intelligence, Inc. Confidential 6 Framework SUnit appears for Smalltalk language in 1998 . Designed by LibreOffice, Kubuntu 14.04 Historical reference Testing SUnit represented structure and functionality to xUnit. CppUnit - a framework for C ++ DUnit - the tool for the environment of development of Delphi JUnit - library for Java NUnit - environment a unit testing for .NET phpUnit - library for PHP vbUnit - Visual Basic JsUnit (Jasmine) - JavaScript
  • 7. © 2015 Return on Intelligence, Inc. Confidential 7 What are Unit Tests Unit Testing is a software testing process by which individual module of source code ... are tested to determine whether they are fit for use. What is the process? What is module ? Process — implementation, writing and run of Unit Tests Module — atomic part of a code Designed by LibreOffice, Kubuntu 14.04 Unit testing, wikipedia
  • 8. © 2015 Return on Intelligence, Inc. Confidential 8 UT - what for they are necessary In the 1990s testing passed to ensuring the quality covering all cycle of development You constantly are engaged in testing (This is integration testing: "Test" buttons or class with name TestServer) Some customers demand a very high level of testing You need to understand how code works You need to write a part of code, but you have no opportunity to test it in actual environment and you exactly know what data will come to methods It isn't necessary to write unit tests, if You do the simple site of 3-5 html-pages with one form of sending the e-mail You are developed a simple flash games or banners You do the project for an exhibition You always write a code without mistakes, you have an ideal brain and gift of anticipation. Your code is so cool that it changes itself according to customer requirements. Periodically the code explains to the customer that his requirements don't need to be realized Designed by LibreOffice, Kubuntu 14.04 Philosophy
  • 9. © 2015 Return on Intelligence, Inc. Confidential 9 What is the Unit Program Module Class Method That you will think up Unit - small self-sufficient part of a code realizing some behavior. Designed by LibreOffice, Kubuntu 14.04 What can be Unit
  • 10. © 2015 Return on Intelligence, Inc. Confidential 10 Approaches in UT UT simple atomic testing TDD (Test-Driven Development) Development through testing. Designed by LibreOffice, Kubuntu 14.04 UT -> TDD -> BDD -> DDT
  • 11. © 2015 Return on Intelligence, Inc. Confidential 11 Approaches in UT BDD (Behavior Driven Development) BDD is further evolution of ideas of TDD. DDT (Data-Driven Testing) Methodology of the testing operated by data. Designed by LibreOffice, Kubuntu 14.04 UT -> TDD -> BDD -> DDT
  • 12. © 2015 Return on Intelligence, Inc. Confidential 12 Without frameworks RDP ? RDP ! Designed by LibreOffice, Kubuntu 14.04 Or how it was earlier ? Frameworks Or how it is now ? RDP. RDP.
  • 13. © 2015 Return on Intelligence, Inc. Confidential 13 Framework JUnit 3 JUnit 4 Java version Java 1.4 Java 1.5 Extends TestCase - Overrides setUp & tearDown annotations Annotations - @Before @After @Test @Ignore Repeated RepeatedTest @Repeat( times = xxx ) UT Frameworks JUnit 3, 4 (Asserts…) Designed by LibreOffice, Kubuntu 14.04
  • 14. © 2015 Return on Intelligence, Inc. Confidential 14 UT Frameworks Designed by LibreOffice, Kubuntu 14.04 TestNG Framework JUnit 4 TestNG Test annotation @Test @Test Start before the suit – @BeforeSuite Start after the suit – @AfterSuite Start before test – @BeforeTest Start after test – @AfterTest Start before test from group – @BeforeGroups Start after test from group – @AfterGroups Start before a class @BeforeClass @BeforeClass Start after a class @AfterClass @AfterClass Start before each test method @Before @BeforeMethod Start after each test method @After @AfterMethod To ignore the test @Ignore @Test(enable=false) To expect an exception @Test (expected = Exception.class) @Test (expectedExceptions = Exception.class) Timeout @Test (timeout = 1000) @Test (timeout = 1000)
  • 15. © 2015 Return on Intelligence, Inc. Confidential 15 UT Frameworks Designed by LibreOffice, Kubuntu 14.04 Addition of dependences into pom.xml JUnit 3 JUnit 4 TestNG <dependencies> ... <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>3.8.1</version> <scope>test</scope> </dependency> </dependencies> <dependencies> ... <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.12</version> <scope>test</scope> </dependency> </dependencies> <dependencies> ... <dependency> <groupId>org.testng</groupId> <artifactId>testng</artifactId> <version>6.9.10</version> <scope>test</scope> </dependency> </dependencies>
  • 16. © 2015 Return on Intelligence, Inc. Confidential 16 Mock frameworks Designed by LibreOffice, Kubuntu 14.04 And additional frameworks JMock Mockito EasyMock EJB Mock Container Equals Verifier Framework JMock Mockito Type Proxy-based Proxy-based Stubbing Yes Yes Default return values 0, empty String, false, empty array, null 0, empty String, false, empty array, null Instances are Strict Non-strict Declarative No Yes Interface additional efforts From box Abstract class additional efforts ? Class additional efforts From box
  • 17. © 2015 Return on Intelligence, Inc. Confidential 17 Mock frameworks Designed by LibreOffice, Kubuntu 14.04 Addition of dependences into pom.xml JMock Mockito Equals Verifier <dependencies> ... <dependency> <groupId>org.jmock</groupId> <artifactId>jmock</artifactId> <version>2.8.1</version> <scope>test</scope> </dependency> </dependencies> <dependencies> ... <dependency> <groupId>org.mockito</groupId> <artifactId>mockito-all</artifactId> <version>1.10.19</version> <scope>test</scope> </dependency> </dependencies> <dependencies> … <dependency> <groupId>nl.jqno.equalsverifier</groupId> <artifactId>equalsverifier</artifactId> <version>1.7.7</version> <scope>test</scope> </dependency> </dependencies>
  • 18. © 2015 Return on Intelligence, Inc. Confidential 18 Code Coverage Designed by LibreOffice, Kubuntu 14.04 Cobertura if (x == 0) { System.out.println("X is zero"); } else { System.out.println("X is invalid"); }
  • 19. © 2015 Return on Intelligence, Inc. Confidential 19 Code Coverage Designed by LibreOffice, Kubuntu 14.04 Addition of Cobertura dependences into pom.xml Dependency section Build section Reporting section <dependencies> ... <dependency> <groupId> net.sourceforge.cobertura </groupId> <artifactId>cobertura</artifactId> <version>2.1.1</version> </dependency> </dependencies> <build> <plugins> ... <plugin> <groupId> org.codehaus.mojo </groupId> <artifactId> cobertura-maven-plugin </artifactId> <version>2.6</version> <configuration> <check> <...Rate> ...</...Rate> </check> <formats> <format>html</format> </formats> <instrumentation> <excludes> <exclude> ... /*.class</exclude> </excludes> </instrumentation> </configuration> </plugin> </plugins> </build> <reporting> <plugins> ... <plugin> <groupId> org.codehaus.mojo </groupId> <artifactId> cobertura-maven- plugin </artifactId> <version>2.6</version> <configuration> <formats> <format>html</format> <format>xml</format> </formats> </configuration> </plugin> </plugins> </reporting>
  • 20. © 2015 Return on Intelligence, Inc. Confidential 20 Automation tests Designed by LibreOffice, Kubuntu 14.04 QTP, Selenium QTP Selenium Commercial tool Open source tool Tests can only be developed in QTP IDE Wide range of IDEs like Visual Studio, Eclipse, Netbeans Oly VB script Supports JAVA, .NET, Ruby, Perl, PHP, and many other User friendly and scripts are developed quickly Script requires more time to develop and high skills Latest version of HP ALM supports code that was developed 5 years back With new release of API the Test Scripts need to be updated
  • 21. © 2015 Return on Intelligence, Inc. Confidential 21 Automation tests Designed by LibreOffice, Kubuntu 14.04 FitNesse
  • 22. © 2015 Return on Intelligence, Inc. Confidential 22 Example Designed by LibreOffice, Kubuntu 14.04 Why UT are necessary
  • 23. © 2015 Return on Intelligence, Inc. Confidential 23 Questions Designed by LibreOffice, Kubuntu 14.04
  • 24. © 2015 Return on Intelligence, Inc. Confidential 24 Links Designed by LibreOffice, Kubuntu 14.04 History of programming languages https://en.wikipedia.org/wiki/History_of_programming_languages TDD https://en.wikipedia.org/wiki/Test-driven_development BDD https://en.wikipedia.org/wiki/Behavior-driven_development xUnit https://en.wikipedia.org/wiki/XUnit JUnit http://junit.org/cookbook.html Open Source Testing Tools in Java http://java-source.net/open-source/testing-tools Cobertura https://github.com/cobertura/cobertura/wiki/Roadmap http://cobertura.github.io/cobertura/ eCobertura (Eclipce plugin) http://ecobertura.johoop.de/ EqualsVerifier http://www.jqno.nl/equalsverifier/
  • 25. © 2015 Return on Intelligence, Inc. Confidential 25 Links to webinars Designed by LibreOffice, Kubuntu 14.04 Вебинар "Introduction to Automation Testing" http://www.returnonintelligence.ru/webinars/introduction-to-automation-testing Вебинар "Code Coverage“ http://www.returnonintelligence.ru/webinars/code-coverage Вебинар "Testing Your Code“ (TDD) http://www.returnonintelligence.ru/webinars/testingyourcode Вебинар "Эволюция к Behavior Driven Development на примере популярного фреймворка JBehave" http://www.returnonintelligence.ru/webinars/bdd