SlideShare une entreprise Scribd logo
1  sur  68
Télécharger pour lire hors ligne
#testinfected
   Mert ÇALIŞKAN



      Feb 2013



                   @ankarajug
                   #testinfected
#testinfected is:
Programmers that
           LOVE
              Writing Tests...
so infected with      of testing
                             @ankarajug
                             #testinfected
AnkaraJUG
  first event @ November 2012...

  Founding Fathers:
    Barış BAL
    Çağatay ÇİVİCİ
    Mert ÇALIŞKAN

http://bit.ly/ankarajugKAYIT
    ankarajug.blogspot.com

    facebook.com/ankarajug

    twitter.com/ankarajug         @ankarajug
                                  #testinfected
Mert ÇALIŞKAN
             10+ years of experience w/ Java
              Coder @ T2.com.tr

Open Source Software Advocate, Founder, Implementor

Member of Apache Software
Foundation and OpenLogic Expert
Community

Author of
PrimeFaces Cookbook
from PacktPub

   tr.linkedin.com/in/mertcaliskan             @ankarajug
                                               #testinfected
We are hiring..!




Send Resumes to   mert@t2.com.tr

                                   @ankarajug
                                   #testinfected
What will I talk about?
   Objectives of Testing

   What to Test, How to Test with

        Java Testing Frameworks

        Unit, Integration, Mock and Functional Testing

   Intensive Code Samples w/ github project

   Test Automation with,


                                        {
                                            Integration
                           Continuous       Inspection
   Concluded with                            Delivery
     Best Practices and Mottos
                                                  @ankarajug
                                                  #testinfected
Do you really need to
       listen to me?
             Please DO..!
The test coverage for the projects that I involved
with was SOOOO damn low.

    So,

      Let’s increase these numbers...!!

                                                @ankarajug
                                                #testinfected
DISCLAIMER

I’m a DEVELOPER..
     so,
      I develop code to test my code...
So you will see
    - coding best practices that I gathered
rather than
    - silver bullets, documentation procedures & etc.

              which is cool, I suppose...
                                               @ankarajug
                                               #testinfected
How many Test Infected
   Zombies among us?


Raise your hand..!




                      @ankarajug
                      #testinfected
Do we need to   TEST?
                        @ankarajug
                        #testinfected
Your Software...after some coding...




                               @ankarajug
                               #testinfected
Your Software...after some coding...




                               @ankarajug
                               #testinfected
Your Software...after some coding...




                               @ankarajug
                               #testinfected
So again,
Do we need to   TEST?
                        @ankarajug
                        #testinfected
webster says that...



        1
test |tɛst|
noun

a procedure intended to establish the quality,
performance, or reliability of something, especially
before it is taken into widespread use...


                                               @ankarajug
                                               #testinfected
webster says that...



        1
test |tɛst|
noun

a procedure intended to establish the quality,
performance, or reliability of something,
especially before it is taken into widespread use...


                                                @ankarajug
                                                #testinfected
The Wh- Questions

WHAT

WHERE

WHEN

WHY

HOW

WHO


                            @ankarajug
                            #testinfected
The Wh- Questions

WHAT to test?

WHERE should we test it?

WHEN should we test it?

WHY do we need to test?

HOW should we test it?

WHO tests it?


                           @ankarajug
                           #testinfected
WHAT to Test?
Unit Tests
  every method...with its every line of code...
Integration Tests
         DAO tests, framework tests...
    (web services, hibernate search and etc)
Mock Tests
   service layer, mocking each other :)

Functional Tests
   UI testing, WS testing
                                           @ankarajug
                                           #testinfected
WHERE should we test it?
                BlackBox      WhiteBox          SmokeTest



           =

  Prod         Staging         Test             Local

Go for 3 different locations other than local
   if it’s applicable.

Try to make Prod and Staging identical...

                                                    @ankarajug
                                                    #testinfected
HOW should we test it?
Unit Tests

    jUnit
Integration Tests

    jUnit along with custom implementations
Mock Tests

   mockito, hamcrest...
Functional Tests

    selenium, soapUI
                                        @ankarajug
                                        #testinfected
How to test
     The Boxing Approach
BlackBox Testing

  you don’t know the internals of the system
  a.k.a. Acceptance Testing

WhiteBox Testing

  Tester knows the design/implementation of the
  system
  a.k.a. Unit/Integration Testing

GrayBox Testing
  Black Box mixed with White Box :)
                                           @ankarajug
                                           #testinfected
Unit Testing

In unit testing, you're just verifying that a single unit
works according to expectations.

Unit tests are not interactive. Once written, they can
be run without further input.

Each test should be responsible for its own actions not
interfere with each other.
                                                   @ankarajug
                                                   #testinfected
Common Rules for
        Testing Frameworks

Each unit test must run independently of all other
unit tests.

Errors must be detected and reported test by test.

It must be easy to define which unit tests will run.



                  JUnit
                                               @ankarajug
                                               #testinfected
JUnit
Founders, Kent Beck and Erich Gamma,
    like ~14 years ago.

Kent Beck the creator of sUnit and tossed the coin on
the term, XP.

Major differences between 3.x and 4.x
 new packaging, annotations and etc...

The Latest and Greatest of jUnit is:   4.11 (use it)


                                                 @ankarajug
                                                 #testinfected
The Simplest Test


                             t
   public class Example {

       @Test
                       T e s
       public void method() {

                             u re
       }
                        ix t
          org.junit.Assert.assertTrue(new ArrayList().isEmpty());

   }
                       F
                                                           @ankarajug
https://gist.github.com/mulderbaba/5013544                 #testinfected
The Simplest Test
public class Example {
  @Test
    public void method() {
       org.junit.Assert.assertTrue(new ArrayList().isEmpty());
    }
}

What happens above?

- jUnit creates a new instance of Example class.
- It invokes the method() which is annotated with Test

                                                        @ankarajug
                                                        #testinfected
The Simplest Test
public class Example {
    @Test
    public void method() {
       org.junit.Assert.assertTrue(new ArrayList().isEmpty());
    }
}


@Test Annotation bundles 2 optional parameters.

expected: the exception that the method should throw.
timeout: the amount of time in ms for the test to fail.

                                                        @ankarajug
                                                        #testinfected
Preparing and Tearing down for tests


@Before
@BeforeClass


                      @After
                      @AfterClass
                                  @ankarajug
                                  #testinfected
Sample @Before and @After
public class SampleTest {

    @Before
    public void setup() {
       / prepare some stuff..
        /
    }

    @Test
    public void checkIfTheCodeWorksOkOrNot() {
       / Some assertions and bla bla...
        /
    }

    @After
    public void tearDown() {
       / tear down all...
        /
    }
}
                                                 @ankarajug
                                                 #testinfected
@BeforeClass and @AfterClass with Question
public class SampleTest {

    @BeforeClass
                                             Question is:
    public void setup() {
       / prepare some stuff..
        /                                    Will it compile?
    }

    @Test
    public void checkIfTheCodeWorksOkOrNot() {
       / Some assertions and bla bla...
        /
    }

    @AfterClass
    public void tearDown() {
       / tear down all...
        /
    }
}
                                                       @ankarajug
                                                       #testinfected
@BeforeClass and @AfterClass with Question
public class SampleTest {

    @BeforeClass
                                             Question is:
    public void setup() {                        YES..!
       / prepare some stuff..
        /                                    Will it compile?
    }

    @Test
    public void checkIfTheCodeWorksOkOrNot() {
       / Some assertions and bla bla...
        /
    }

    @AfterClass
    public void tearDown() {
       / tear down all...
        /
    }
}
                                                       @ankarajug
                                                       #testinfected
@BeforeClass and @AfterClass with Question
public class SampleTest {

    @BeforeClass
                                                   But,
                                             Question is:
    public void setup() {                        YES..!
       / prepare some stuff..
        /                                    will it compile?
                                             Will it work?
    }

    @Test
    public void checkIfTheCodeWorksOkOrNot() {
       / Some assertions and bla bla...
        /
    }

    @AfterClass
    public void tearDown() {
       / tear down all...
        /
    }
}
                                                       @ankarajug
                                                       #testinfected
Multiple methods with @Before or @After annotations?
   public class BeforeOrderSample {
      @Before
      public void finalSetup() {
          System.out.println("final stuff");
      }
                                                  Question is:
       @Test                                      Will it work?
       public void doTheTest() {
          System.out.println("test test test");   If so,
       }                                          which method
                                                  works first?
       @Before
       public void initialSetup() {
          System.out.println("initial stuff");
       }
   }
                                                            @ankarajug
https://gist.github.com/mulderbaba/5013850                  #testinfected
Let’s introduce some inheritance :)
                    @Before
                    public void classASetup() {
    Class A         }
                       System.out.println("class A setup");


                    @After
                    public void classATearDown() {
                       System.out.println("class A tear down");
                    }

                   @Before
                   public void classBSetup() {
                      System.out.println("class B setup");   @Test
                   }
                                                             public void doTheTest() {
    Class B        @After
                                                                System.out.println("test test test");
                                                             }
                   public void classBTearDown() {
                      System.out.println("class B tear down");
                   }


                                                                                       @ankarajug
https://gist.github.com/mulderbaba/5014153                                             #testinfected
Let’s introduce some inheritance :)
                    @Before                           1
                    public void classASetup() {
    Class A         }
                       System.out.println("class A setup");


                    @After             5
                    public void classATearDown() {
                       System.out.println("class A tear down");
                    }

                   @Before                        2
                   public void classBSetup() {
                      System.out.println("class B setup");   @Test
                                                                            3
                   }
                                                             public void doTheTest() {
    Class B        @After
                                     4                          System.out.println("test test test");
                                                             }
                   public void classBTearDown() {
                      System.out.println("class B tear down");
                   }


                                                                                       @ankarajug
https://gist.github.com/mulderbaba/5014153                                             #testinfected
Test Methods’ Execution Order

  public class TestCasesExecutionOrder {

      @Test
      public void secondTest() {
         System.out.println("Executing second test");
      }
                                                        Question is:
      @Test
      public void firstTest() {                          What’s the
         System.out.println("Executing first test");     execution order?
      }

      @Test
      public void thirdTest() {
         System.out.println("Executing third test");
      }
  }
                                                                  @ankarajug
https://gist.github.com/mulderbaba/5014568                        #testinfected
Test Methods’ Execution Order
  @FixMethodOrder(MethodSorters.NAME_ASCENDING)
  public class TestCasesExecutionOrder {

      @Test
      public void secondTest() {
         System.out.println("Executing second test");
      }
                                                        Question is:
      @Test
      public void firstTest() {                          What’s the
         System.out.println("Executing first test");     execution order?
      }

      @Test
      public void thirdTest() {
         System.out.println("Executing third test");
      }
  }
                                                                  @ankarajug
https://gist.github.com/mulderbaba/5014568                        #testinfected
My Way or the                      Way



           For Unit Testing
surefire    Attached to test phase



           For Integration Tests
failsafe   Attached to pre-integration-test phase and
           others...




                                                @ankarajug
                                                #testinfected
testinfected demo @ github
2 projects (demo + template) available at
     http://github.com/mulderbaba/testinfected
fork it and enjoy it..

  demo is for demo as it is named...
   template is a brand new beginning...template for all the
frameworks with testing infrastructure...


 PrimeFaces          CXF               Hamcrest Mockito
                            Spring
   JPA        Hibernate                      jUnit
                                                     @ankarajug
                                                     #testinfected
Code Walkthrough




  Unit Testing
                   @ankarajug
                   #testinfected
Integration Tests

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = {"/applicationContext-test.xml"})
@TransactionConfiguration(defaultRollback = false,
                         transactionManager = "transactionManager")

public abstract class BaseIntegrationTestCase {
}



          What’s with this class?

                                                           @ankarajug
                                                           #testinfected
Integration Tests

Framework testing is one of the coolest things...

You can even test Web Services like,

  Get Jetty UP

  Create a client

  Did a WS call

  Assert the result
                                                    @ankarajug
                                                    #testinfected
First Rules First...

Differentiate your DB’s...




       PROD                  DEV     TEST




        Use an ORM (JPA, Hibernate, bla bla)

              But WHY o’WHY...?
                                               @ankarajug
                                               #testinfected
First Rules First...

Differentiate your DB’s...




       PROD                  DEV          TEST

          C LE            SQL                  L DB
  ORA                   MY              HS   Q
Always go for in memory DB for Testing environment.

Everything will vanish so you can do anything you want.

And you can easily tests frameworks like Hibernate Search
                                                      @ankarajug
                                                      #testinfected
Case Study: Quartz Scheduling
                     Testing
           Question is: How would you test it?

@Service
public class SomePrettySophisticatedJob {
   @Autowired
   private SomePrettySophisticatedService1 service;
   private SomePrettySophisticatedService2 service;
   private SomePrettySophisticatedService3 service;

    @Scheduled(fixedDelay=500)
    public void execute() {
      //Some heavy duty coding...
      service calls, calls, calls, computations and bla bla..
    }
}
                                                                @ankarajug
                                                                #testinfected
Quartz Scheduling Testing

Well you don’t need to test it, it’s a framework remember?
and since it’s a well-known one, just use it for scheduling.
It will work..trust me..

@Service
public class SomePrettySophisticatedJob {
   @Autowired
   private GatheredPrettySophisticatedService service;

    @Scheduled(fixedDelay=500)
    public void execute() {
      service.execute();
    }
}                                                        @ankarajug
                                                         #testinfected
Code Walkthrough




Integration Testing
                      @ankarajug
                      #testinfected
Anatomy of a Mock Test

It’s good for service layer testing.

Set your expectations, do the service layer call,
verify the calls and assert the results.
@RunWith(MockitoJUnitRunner.class)
public class CalculatorServiceImplTest {
   @Mock
   private CalculatorDao dao;

   @InjectMocks
   private CalculatorServiceImpl impl = new CalculatorServiceImpl();



                                                                       @ankarajug
                                                                       #testinfected
Anatomy of a Mock Test


@Test
public void addInvokedSuccessfully() {
  impl.add(4, 5);

    verify(dao).save(any(CalculationResult.class));
}




                                                      @ankarajug
                                                      #testinfected
Anatomy of a Mock Test


@Test
public void addInvokedSuccessfully() {
  when(helper.retrieveSomeStuff()).
                       thenReturn(someNiceInstance);
  impl.add(4, 5);

    verify(dao).save(any(CalculationResult.class));
}




                                                       @ankarajug
                                                       #testinfected
Anatomy of a Mock Test

Always use static imports while using Matchers...

Also see other annotations,
 @Spy

 @Captor

little something something on the topic:

http://www.jroller.com/mert/entry/anatomy_of_a_mock_test



                                                           @ankarajug
                                                           #testinfected
Functional Testing

Enough with coding..!
   let’s see that it just works.. mode on...

UI Testing with Selenium with the IDE

Web Service Testing with SoapUI

  Functional Testing

  Load Testing

jMeter Performance Testing

                                               @ankarajug
                                               #testinfected
Code Walkthrough




      Mock Testing
    Functional Testing
(SoapUI, jMeter, Selenium)   @ankarajug
                             #testinfected
Continuous Integration leads to
         Continuous Delivery

So you have 10.000 tests...
Congratz..!
But...
They’ll be useless if developers need to
run them by hand every time..!
We need a build triggered with each
commit, right?
                                     @ankarajug
                                     #testinfected
Continuous Integration Tools
          out in the field




          Hudson




Jenkins                            @ankarajug
                                   #testinfected
Release Life Cycle
               Demystified
Pre-Alpha




             }
                   Release



                                  }
                  Candidate
                                       General
 Alpha                                Availability
                                         (GA)
                   Release to
                  Manufacturing
                     (RTM)


  Beta



                                                     @ankarajug
                                                     #testinfected
Release Life Cycle
Pre-Alpha     More of an idea in development...
              with nightly builds..milestones..
  testing phase                                               ox
                                                            eB x
               Working draft but probably w/ lots W k    hit Bo
 Alpha                                                   lac Box
               of bugs...do extensive testing on it...! B ey
  feature   freeze                                        Gr

              The prototype..features are complete..!
  Beta
              first time available to the outsiders
              (open/closed beta)

             The radiation level is high..! but not relevant of course, since
             these are the first 2 letters of greek alphabet..
                                                                           @ankarajug
                                                                           #testinfected
Release Life Cycle
  code complete


  Release        all features implemented/tested
 Candidate       call for a “code complete". you have the
                 candidate..!
  ready to release

 Release to      You are ready to go mass manufacturing.
Manufacturing    hardware + software bundled together.
   (RTM)

  ready to advertise

  General        You are now live..! you did all the commercial
 Availability
    (GA)
                 stuff and you are good to go.. just sell it..!!!


                                                            @ankarajug
                                                            #testinfected
Continuous Integration
  DEMO w/ Jenkins




                         @ankarajug
                         #testinfected
Continuous Inspection

Metric dashboard for,

  Test & Code Coverage (cobertura)

  Coding Violations (checkstyle)

Triggering at each build so you’ll have incremental reports.

For installation and getting it up and running you need to,

  configure its DB,

  hook it with Jenkins to make more sense...

                                                     @ankarajug
                                                     #testinfected
Continuous Inspection
  DEMO w/ Sonar




                        @ankarajug
                        #testinfected
Continuous Integration and Inspection
             DEMO with
        BAMBOO and CLOVER




             Kerem ÇAĞLAR
             Solveka Yazılım      @ankarajug
                                  #testinfected
Best Practices

Use Matchers with static imports...
Assert.assertEquals(result.getResult().doubleValue(), 9.0);

assertThat(result.getResult(), is(9.0));

Test method names can be long, no worries.
They should be understood when read by someone
like,
retrieveListStatusByNationalIdReturnsOneElementWh
enThereIsManuallyAddedPersonWithExemptedInfo()

                                                        @ankarajug
                                                        #testinfected
Some
Whenever you are tempted to type something into a print
statement or a debugger expression, write it as a test instead

                                               (Martin Fowler)

Code without automated test simply doesn’t exist.

Once you get them running, make sure they stay running.

If you can’t test it, just trash it.


                                                        @ankarajug
                                                        #testinfected
Some
We do not need private methods, get rid of them..!

Run the fast tests first.. group them.. If they fail you’ll get
notified early.

Test your app with different localizations (for sorting and etc.)

Increase your coverage for sleeping tight at night.

Keep the bar green to keep the code clean.

You want to test the code, not yourself. Don’t be the
keyboard monkey...
                                                         @ankarajug
                                                         #testinfected
You cannot test EVERYTHING..!
                            @ankarajug
                            #testinfected
@ankarajug
#testinfected

Contenu connexe

Tendances

Java Unit Test and Coverage Introduction
Java Unit Test and Coverage IntroductionJava Unit Test and Coverage Introduction
Java Unit Test and Coverage IntroductionAlex Su
 
JUnit- A Unit Testing Framework
JUnit- A Unit Testing FrameworkJUnit- A Unit Testing Framework
JUnit- A Unit Testing FrameworkOnkar Deshpande
 
Automated Unit Testing
Automated Unit TestingAutomated Unit Testing
Automated Unit TestingMike Lively
 
Advanced junit and mockito
Advanced junit and mockitoAdvanced junit and mockito
Advanced junit and mockitoMathieu Carbou
 
Simple Unit Testing With Netbeans 6.1
Simple Unit Testing With Netbeans 6.1Simple Unit Testing With Netbeans 6.1
Simple Unit Testing With Netbeans 6.1Kiki Ahmadi
 
05 junit
05 junit05 junit
05 junitmha4
 
Writing good unit test
Writing good unit testWriting good unit test
Writing good unit testLucy Lu
 
.Net Unit Testing with Visual Studio 2010
.Net Unit Testing with Visual Studio 2010.Net Unit Testing with Visual Studio 2010
.Net Unit Testing with Visual Studio 2010kgayda
 
Clean Unit Test Patterns
Clean Unit Test PatternsClean Unit Test Patterns
Clean Unit Test PatternsFrank Appel
 
Introduction To J unit
Introduction To J unitIntroduction To J unit
Introduction To J unitOlga Extone
 
Unit Test Presentation
Unit Test PresentationUnit Test Presentation
Unit Test PresentationSayedur Rahman
 

Tendances (20)

Unit testing with JUnit
Unit testing with JUnitUnit testing with JUnit
Unit testing with JUnit
 
Java Unit Test and Coverage Introduction
Java Unit Test and Coverage IntroductionJava Unit Test and Coverage Introduction
Java Unit Test and Coverage Introduction
 
Unit testing, principles
Unit testing, principlesUnit testing, principles
Unit testing, principles
 
JUnit- A Unit Testing Framework
JUnit- A Unit Testing FrameworkJUnit- A Unit Testing Framework
JUnit- A Unit Testing Framework
 
Automated Unit Testing
Automated Unit TestingAutomated Unit Testing
Automated Unit Testing
 
Advanced junit and mockito
Advanced junit and mockitoAdvanced junit and mockito
Advanced junit and mockito
 
Simple Unit Testing With Netbeans 6.1
Simple Unit Testing With Netbeans 6.1Simple Unit Testing With Netbeans 6.1
Simple Unit Testing With Netbeans 6.1
 
05 junit
05 junit05 junit
05 junit
 
Writing good unit test
Writing good unit testWriting good unit test
Writing good unit test
 
Workshop unit test
Workshop   unit testWorkshop   unit test
Workshop unit test
 
Java Unit Testing
Java Unit TestingJava Unit Testing
Java Unit Testing
 
JUnit 5
JUnit 5JUnit 5
JUnit 5
 
JUNit Presentation
JUNit PresentationJUNit Presentation
JUNit Presentation
 
.Net Unit Testing with Visual Studio 2010
.Net Unit Testing with Visual Studio 2010.Net Unit Testing with Visual Studio 2010
.Net Unit Testing with Visual Studio 2010
 
Clean Unit Test Patterns
Clean Unit Test PatternsClean Unit Test Patterns
Clean Unit Test Patterns
 
JUnit Presentation
JUnit PresentationJUnit Presentation
JUnit Presentation
 
Introduction To J unit
Introduction To J unitIntroduction To J unit
Introduction To J unit
 
Best practices unit testing
Best practices unit testing Best practices unit testing
Best practices unit testing
 
Unit Test Presentation
Unit Test PresentationUnit Test Presentation
Unit Test Presentation
 
testng
testngtestng
testng
 

Similaire à Test Infected

Make good use of explortary testing
Make good use of explortary testingMake good use of explortary testing
Make good use of explortary testinggaoliang641
 
A Beginer's Guide to testing in Django
A Beginer's Guide to testing in DjangoA Beginer's Guide to testing in Django
A Beginer's Guide to testing in DjangoPsalms Kalu
 
TestNG vs JUnit: cease fire or the end of the war
TestNG vs JUnit: cease fire or the end of the warTestNG vs JUnit: cease fire or the end of the war
TestNG vs JUnit: cease fire or the end of the warOleksiy Rezchykov
 
An Introduction to unit testing
An Introduction to unit testingAn Introduction to unit testing
An Introduction to unit testingSteven Casey
 
Dev labs alliance top 20 testng interview questions for sdet
Dev labs alliance top 20 testng interview questions for sdetDev labs alliance top 20 testng interview questions for sdet
Dev labs alliance top 20 testng interview questions for sdetdevlabsalliance
 
Software Testing
Software TestingSoftware Testing
Software TestingAdroitLogic
 
Getting started with Test Driven Development
Getting started with Test Driven DevelopmentGetting started with Test Driven Development
Getting started with Test Driven DevelopmentFerdous Mahmud Shaon
 
Unit Testing Guidelines
Unit Testing GuidelinesUnit Testing Guidelines
Unit Testing GuidelinesJoel Hooks
 
Break through e2e-testing
Break through e2e-testingBreak through e2e-testing
Break through e2e-testingtameemahmed5
 
Getting started with Test Driven Development - Ferdous Mahmud Shaon
Getting started with Test Driven Development - Ferdous Mahmud ShaonGetting started with Test Driven Development - Ferdous Mahmud Shaon
Getting started with Test Driven Development - Ferdous Mahmud ShaonCefalo
 
A la découverte des google/mock (aka gmock)
A la découverte des google/mock (aka gmock)A la découverte des google/mock (aka gmock)
A la découverte des google/mock (aka gmock)Thierry Gayet
 
An Introduction to Test Driven Development
An Introduction to Test Driven Development An Introduction to Test Driven Development
An Introduction to Test Driven Development CodeOps Technologies LLP
 
Unit testing in xcode 8 with swift
Unit testing in xcode 8 with swiftUnit testing in xcode 8 with swift
Unit testing in xcode 8 with swiftallanh0526
 

Similaire à Test Infected (20)

Unit Testing
Unit TestingUnit Testing
Unit Testing
 
TDD Best Practices
TDD Best PracticesTDD Best Practices
TDD Best Practices
 
Make good use of explortary testing
Make good use of explortary testingMake good use of explortary testing
Make good use of explortary testing
 
A Beginer's Guide to testing in Django
A Beginer's Guide to testing in DjangoA Beginer's Guide to testing in Django
A Beginer's Guide to testing in Django
 
TestNG vs JUnit: cease fire or the end of the war
TestNG vs JUnit: cease fire or the end of the warTestNG vs JUnit: cease fire or the end of the war
TestNG vs JUnit: cease fire or the end of the war
 
TDD Workshop UTN 2012
TDD Workshop UTN 2012TDD Workshop UTN 2012
TDD Workshop UTN 2012
 
An Introduction to unit testing
An Introduction to unit testingAn Introduction to unit testing
An Introduction to unit testing
 
Dev labs alliance top 20 testng interview questions for sdet
Dev labs alliance top 20 testng interview questions for sdetDev labs alliance top 20 testng interview questions for sdet
Dev labs alliance top 20 testng interview questions for sdet
 
TDD and Getting Paid
TDD and Getting PaidTDD and Getting Paid
TDD and Getting Paid
 
Testacular
TestacularTestacular
Testacular
 
Software Testing
Software TestingSoftware Testing
Software Testing
 
Getting started with Test Driven Development
Getting started with Test Driven DevelopmentGetting started with Test Driven Development
Getting started with Test Driven Development
 
Unit Testing Guidelines
Unit Testing GuidelinesUnit Testing Guidelines
Unit Testing Guidelines
 
Break through e2e-testing
Break through e2e-testingBreak through e2e-testing
Break through e2e-testing
 
Getting started with Test Driven Development - Ferdous Mahmud Shaon
Getting started with Test Driven Development - Ferdous Mahmud ShaonGetting started with Test Driven Development - Ferdous Mahmud Shaon
Getting started with Test Driven Development - Ferdous Mahmud Shaon
 
A la découverte des google/mock (aka gmock)
A la découverte des google/mock (aka gmock)A la découverte des google/mock (aka gmock)
A la découverte des google/mock (aka gmock)
 
An Introduction to Test Driven Development
An Introduction to Test Driven Development An Introduction to Test Driven Development
An Introduction to Test Driven Development
 
Unit testing in xcode 8 with swift
Unit testing in xcode 8 with swiftUnit testing in xcode 8 with swift
Unit testing in xcode 8 with swift
 
Grails Spock Testing
Grails Spock TestingGrails Spock Testing
Grails Spock Testing
 
Unit testing in PHP
Unit testing in PHPUnit testing in PHP
Unit testing in PHP
 

Plus de Mert Çalışkan

MicroProfile for MicroServices
MicroProfile for MicroServicesMicroProfile for MicroServices
MicroProfile for MicroServicesMert Çalışkan
 
jDays2015 - JavaEE vs. Spring Smackdown
jDays2015 - JavaEE vs. Spring SmackdownjDays2015 - JavaEE vs. Spring Smackdown
jDays2015 - JavaEE vs. Spring SmackdownMert Çalışkan
 
BMO - Intelligent Projects with Maven
BMO - Intelligent Projects with MavenBMO - Intelligent Projects with Maven
BMO - Intelligent Projects with MavenMert Çalışkan
 
Intelligent Projects with Maven - DevFest Istanbul
Intelligent Projects with Maven - DevFest IstanbulIntelligent Projects with Maven - DevFest Istanbul
Intelligent Projects with Maven - DevFest IstanbulMert Çalışkan
 
JavaOne - 10 Tips for Java EE 7 with PrimeFaces
JavaOne - 10 Tips for Java EE 7 with PrimeFacesJavaOne - 10 Tips for Java EE 7 with PrimeFaces
JavaOne - 10 Tips for Java EE 7 with PrimeFacesMert Çalışkan
 
Gelecex - Maven ile Akilli Projeler
Gelecex - Maven ile Akilli ProjelerGelecex - Maven ile Akilli Projeler
Gelecex - Maven ile Akilli ProjelerMert Çalışkan
 
Jdc 2010 - Maven, Intelligent Projects
Jdc 2010 - Maven, Intelligent ProjectsJdc 2010 - Maven, Intelligent Projects
Jdc 2010 - Maven, Intelligent ProjectsMert Çalışkan
 
Enterprise Java Web Application Frameworks Sample Stack Implementation
Enterprise Java Web Application Frameworks   Sample Stack ImplementationEnterprise Java Web Application Frameworks   Sample Stack Implementation
Enterprise Java Web Application Frameworks Sample Stack ImplementationMert Çalışkan
 

Plus de Mert Çalışkan (10)

MicroProfile for MicroServices
MicroProfile for MicroServicesMicroProfile for MicroServices
MicroProfile for MicroServices
 
jDays2015 - JavaEE vs. Spring Smackdown
jDays2015 - JavaEE vs. Spring SmackdownjDays2015 - JavaEE vs. Spring Smackdown
jDays2015 - JavaEE vs. Spring Smackdown
 
BMO - Intelligent Projects with Maven
BMO - Intelligent Projects with MavenBMO - Intelligent Projects with Maven
BMO - Intelligent Projects with Maven
 
Intelligent Projects with Maven - DevFest Istanbul
Intelligent Projects with Maven - DevFest IstanbulIntelligent Projects with Maven - DevFest Istanbul
Intelligent Projects with Maven - DevFest Istanbul
 
JavaOne - 10 Tips for Java EE 7 with PrimeFaces
JavaOne - 10 Tips for Java EE 7 with PrimeFacesJavaOne - 10 Tips for Java EE 7 with PrimeFaces
JavaOne - 10 Tips for Java EE 7 with PrimeFaces
 
Better Career with Java
Better Career with JavaBetter Career with Java
Better Career with Java
 
Gelecex - Maven ile Akilli Projeler
Gelecex - Maven ile Akilli ProjelerGelecex - Maven ile Akilli Projeler
Gelecex - Maven ile Akilli Projeler
 
Jdc 2010 - Maven, Intelligent Projects
Jdc 2010 - Maven, Intelligent ProjectsJdc 2010 - Maven, Intelligent Projects
Jdc 2010 - Maven, Intelligent Projects
 
Fikrim Acik Kodum Acik
Fikrim Acik Kodum AcikFikrim Acik Kodum Acik
Fikrim Acik Kodum Acik
 
Enterprise Java Web Application Frameworks Sample Stack Implementation
Enterprise Java Web Application Frameworks   Sample Stack ImplementationEnterprise Java Web Application Frameworks   Sample Stack Implementation
Enterprise Java Web Application Frameworks Sample Stack Implementation
 

Dernier

APIForce Zurich 5 April Automation LPDG
APIForce Zurich 5 April  Automation LPDGAPIForce Zurich 5 April  Automation LPDG
APIForce Zurich 5 April Automation LPDGMarianaLemus7
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024Scott Keck-Warren
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsMemoori
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Alan Dix
 
Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024Neo4j
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksSoftradix Technologies
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersThousandEyes
 
Artificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraArtificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraDeakin University
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Scott Keck-Warren
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions
 
Science&tech:THE INFORMATION AGE STS.pdf
Science&tech:THE INFORMATION AGE STS.pdfScience&tech:THE INFORMATION AGE STS.pdf
Science&tech:THE INFORMATION AGE STS.pdfjimielynbastida
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptxLBM Solutions
 
Snow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter RoadsSnow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter RoadsHyundai Motor Group
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticscarlostorres15106
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 

Dernier (20)

APIForce Zurich 5 April Automation LPDG
APIForce Zurich 5 April  Automation LPDGAPIForce Zurich 5 April  Automation LPDG
APIForce Zurich 5 April Automation LPDG
 
Vulnerability_Management_GRC_by Sohang Sengupta.pptx
Vulnerability_Management_GRC_by Sohang Sengupta.pptxVulnerability_Management_GRC_by Sohang Sengupta.pptx
Vulnerability_Management_GRC_by Sohang Sengupta.pptx
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial Buildings
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
 
Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other Frameworks
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
 
Artificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraArtificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning era
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping Elbows
 
Science&tech:THE INFORMATION AGE STS.pdf
Science&tech:THE INFORMATION AGE STS.pdfScience&tech:THE INFORMATION AGE STS.pdf
Science&tech:THE INFORMATION AGE STS.pdf
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptx
 
Snow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter RoadsSnow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter Roads
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 

Test Infected

  • 1. #testinfected Mert ÇALIŞKAN Feb 2013 @ankarajug #testinfected
  • 2. #testinfected is: Programmers that LOVE Writing Tests... so infected with of testing @ankarajug #testinfected
  • 3. AnkaraJUG first event @ November 2012... Founding Fathers: Barış BAL Çağatay ÇİVİCİ Mert ÇALIŞKAN http://bit.ly/ankarajugKAYIT ankarajug.blogspot.com facebook.com/ankarajug twitter.com/ankarajug @ankarajug #testinfected
  • 4. Mert ÇALIŞKAN 10+ years of experience w/ Java Coder @ T2.com.tr Open Source Software Advocate, Founder, Implementor Member of Apache Software Foundation and OpenLogic Expert Community Author of PrimeFaces Cookbook from PacktPub tr.linkedin.com/in/mertcaliskan @ankarajug #testinfected
  • 5. We are hiring..! Send Resumes to mert@t2.com.tr @ankarajug #testinfected
  • 6. What will I talk about? Objectives of Testing What to Test, How to Test with Java Testing Frameworks Unit, Integration, Mock and Functional Testing Intensive Code Samples w/ github project Test Automation with, { Integration Continuous Inspection Concluded with Delivery Best Practices and Mottos @ankarajug #testinfected
  • 7. Do you really need to listen to me? Please DO..! The test coverage for the projects that I involved with was SOOOO damn low. So, Let’s increase these numbers...!! @ankarajug #testinfected
  • 8. DISCLAIMER I’m a DEVELOPER.. so, I develop code to test my code... So you will see - coding best practices that I gathered rather than - silver bullets, documentation procedures & etc. which is cool, I suppose... @ankarajug #testinfected
  • 9. How many Test Infected Zombies among us? Raise your hand..! @ankarajug #testinfected
  • 10. Do we need to TEST? @ankarajug #testinfected
  • 11. Your Software...after some coding... @ankarajug #testinfected
  • 12. Your Software...after some coding... @ankarajug #testinfected
  • 13. Your Software...after some coding... @ankarajug #testinfected
  • 14. So again, Do we need to TEST? @ankarajug #testinfected
  • 15. webster says that... 1 test |tɛst| noun a procedure intended to establish the quality, performance, or reliability of something, especially before it is taken into widespread use... @ankarajug #testinfected
  • 16. webster says that... 1 test |tɛst| noun a procedure intended to establish the quality, performance, or reliability of something, especially before it is taken into widespread use... @ankarajug #testinfected
  • 18. The Wh- Questions WHAT to test? WHERE should we test it? WHEN should we test it? WHY do we need to test? HOW should we test it? WHO tests it? @ankarajug #testinfected
  • 19. WHAT to Test? Unit Tests every method...with its every line of code... Integration Tests DAO tests, framework tests... (web services, hibernate search and etc) Mock Tests service layer, mocking each other :) Functional Tests UI testing, WS testing @ankarajug #testinfected
  • 20. WHERE should we test it? BlackBox WhiteBox SmokeTest = Prod Staging Test Local Go for 3 different locations other than local if it’s applicable. Try to make Prod and Staging identical... @ankarajug #testinfected
  • 21. HOW should we test it? Unit Tests jUnit Integration Tests jUnit along with custom implementations Mock Tests mockito, hamcrest... Functional Tests selenium, soapUI @ankarajug #testinfected
  • 22. How to test The Boxing Approach BlackBox Testing you don’t know the internals of the system a.k.a. Acceptance Testing WhiteBox Testing Tester knows the design/implementation of the system a.k.a. Unit/Integration Testing GrayBox Testing Black Box mixed with White Box :) @ankarajug #testinfected
  • 23. Unit Testing In unit testing, you're just verifying that a single unit works according to expectations. Unit tests are not interactive. Once written, they can be run without further input. Each test should be responsible for its own actions not interfere with each other. @ankarajug #testinfected
  • 24. Common Rules for Testing Frameworks Each unit test must run independently of all other unit tests. Errors must be detected and reported test by test. It must be easy to define which unit tests will run. JUnit @ankarajug #testinfected
  • 25. JUnit Founders, Kent Beck and Erich Gamma, like ~14 years ago. Kent Beck the creator of sUnit and tossed the coin on the term, XP. Major differences between 3.x and 4.x new packaging, annotations and etc... The Latest and Greatest of jUnit is: 4.11 (use it) @ankarajug #testinfected
  • 26. The Simplest Test t public class Example { @Test T e s public void method() { u re } ix t org.junit.Assert.assertTrue(new ArrayList().isEmpty()); } F @ankarajug https://gist.github.com/mulderbaba/5013544 #testinfected
  • 27. The Simplest Test public class Example { @Test public void method() { org.junit.Assert.assertTrue(new ArrayList().isEmpty()); } } What happens above? - jUnit creates a new instance of Example class. - It invokes the method() which is annotated with Test @ankarajug #testinfected
  • 28. The Simplest Test public class Example { @Test public void method() { org.junit.Assert.assertTrue(new ArrayList().isEmpty()); } } @Test Annotation bundles 2 optional parameters. expected: the exception that the method should throw. timeout: the amount of time in ms for the test to fail. @ankarajug #testinfected
  • 29. Preparing and Tearing down for tests @Before @BeforeClass @After @AfterClass @ankarajug #testinfected
  • 30. Sample @Before and @After public class SampleTest { @Before public void setup() { / prepare some stuff.. / } @Test public void checkIfTheCodeWorksOkOrNot() { / Some assertions and bla bla... / } @After public void tearDown() { / tear down all... / } } @ankarajug #testinfected
  • 31. @BeforeClass and @AfterClass with Question public class SampleTest { @BeforeClass Question is: public void setup() { / prepare some stuff.. / Will it compile? } @Test public void checkIfTheCodeWorksOkOrNot() { / Some assertions and bla bla... / } @AfterClass public void tearDown() { / tear down all... / } } @ankarajug #testinfected
  • 32. @BeforeClass and @AfterClass with Question public class SampleTest { @BeforeClass Question is: public void setup() { YES..! / prepare some stuff.. / Will it compile? } @Test public void checkIfTheCodeWorksOkOrNot() { / Some assertions and bla bla... / } @AfterClass public void tearDown() { / tear down all... / } } @ankarajug #testinfected
  • 33. @BeforeClass and @AfterClass with Question public class SampleTest { @BeforeClass But, Question is: public void setup() { YES..! / prepare some stuff.. / will it compile? Will it work? } @Test public void checkIfTheCodeWorksOkOrNot() { / Some assertions and bla bla... / } @AfterClass public void tearDown() { / tear down all... / } } @ankarajug #testinfected
  • 34. Multiple methods with @Before or @After annotations? public class BeforeOrderSample { @Before public void finalSetup() { System.out.println("final stuff"); } Question is: @Test Will it work? public void doTheTest() { System.out.println("test test test"); If so, } which method works first? @Before public void initialSetup() { System.out.println("initial stuff"); } } @ankarajug https://gist.github.com/mulderbaba/5013850 #testinfected
  • 35. Let’s introduce some inheritance :) @Before public void classASetup() { Class A } System.out.println("class A setup"); @After public void classATearDown() { System.out.println("class A tear down"); } @Before public void classBSetup() { System.out.println("class B setup"); @Test } public void doTheTest() { Class B @After System.out.println("test test test"); } public void classBTearDown() { System.out.println("class B tear down"); } @ankarajug https://gist.github.com/mulderbaba/5014153 #testinfected
  • 36. Let’s introduce some inheritance :) @Before 1 public void classASetup() { Class A } System.out.println("class A setup"); @After 5 public void classATearDown() { System.out.println("class A tear down"); } @Before 2 public void classBSetup() { System.out.println("class B setup"); @Test 3 } public void doTheTest() { Class B @After 4 System.out.println("test test test"); } public void classBTearDown() { System.out.println("class B tear down"); } @ankarajug https://gist.github.com/mulderbaba/5014153 #testinfected
  • 37. Test Methods’ Execution Order public class TestCasesExecutionOrder { @Test public void secondTest() { System.out.println("Executing second test"); } Question is: @Test public void firstTest() { What’s the System.out.println("Executing first test"); execution order? } @Test public void thirdTest() { System.out.println("Executing third test"); } } @ankarajug https://gist.github.com/mulderbaba/5014568 #testinfected
  • 38. Test Methods’ Execution Order @FixMethodOrder(MethodSorters.NAME_ASCENDING) public class TestCasesExecutionOrder { @Test public void secondTest() { System.out.println("Executing second test"); } Question is: @Test public void firstTest() { What’s the System.out.println("Executing first test"); execution order? } @Test public void thirdTest() { System.out.println("Executing third test"); } } @ankarajug https://gist.github.com/mulderbaba/5014568 #testinfected
  • 39. My Way or the Way For Unit Testing surefire Attached to test phase For Integration Tests failsafe Attached to pre-integration-test phase and others... @ankarajug #testinfected
  • 40. testinfected demo @ github 2 projects (demo + template) available at http://github.com/mulderbaba/testinfected fork it and enjoy it.. demo is for demo as it is named... template is a brand new beginning...template for all the frameworks with testing infrastructure... PrimeFaces CXF Hamcrest Mockito Spring JPA Hibernate jUnit @ankarajug #testinfected
  • 41. Code Walkthrough Unit Testing @ankarajug #testinfected
  • 42. Integration Tests @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(locations = {"/applicationContext-test.xml"}) @TransactionConfiguration(defaultRollback = false, transactionManager = "transactionManager") public abstract class BaseIntegrationTestCase { } What’s with this class? @ankarajug #testinfected
  • 43. Integration Tests Framework testing is one of the coolest things... You can even test Web Services like, Get Jetty UP Create a client Did a WS call Assert the result @ankarajug #testinfected
  • 44. First Rules First... Differentiate your DB’s... PROD DEV TEST Use an ORM (JPA, Hibernate, bla bla) But WHY o’WHY...? @ankarajug #testinfected
  • 45. First Rules First... Differentiate your DB’s... PROD DEV TEST C LE SQL L DB ORA MY HS Q Always go for in memory DB for Testing environment. Everything will vanish so you can do anything you want. And you can easily tests frameworks like Hibernate Search @ankarajug #testinfected
  • 46. Case Study: Quartz Scheduling Testing Question is: How would you test it? @Service public class SomePrettySophisticatedJob { @Autowired private SomePrettySophisticatedService1 service; private SomePrettySophisticatedService2 service; private SomePrettySophisticatedService3 service; @Scheduled(fixedDelay=500) public void execute() { //Some heavy duty coding... service calls, calls, calls, computations and bla bla.. } } @ankarajug #testinfected
  • 47. Quartz Scheduling Testing Well you don’t need to test it, it’s a framework remember? and since it’s a well-known one, just use it for scheduling. It will work..trust me.. @Service public class SomePrettySophisticatedJob { @Autowired private GatheredPrettySophisticatedService service; @Scheduled(fixedDelay=500) public void execute() { service.execute(); } } @ankarajug #testinfected
  • 48. Code Walkthrough Integration Testing @ankarajug #testinfected
  • 49. Anatomy of a Mock Test It’s good for service layer testing. Set your expectations, do the service layer call, verify the calls and assert the results. @RunWith(MockitoJUnitRunner.class) public class CalculatorServiceImplTest { @Mock private CalculatorDao dao; @InjectMocks private CalculatorServiceImpl impl = new CalculatorServiceImpl(); @ankarajug #testinfected
  • 50. Anatomy of a Mock Test @Test public void addInvokedSuccessfully() { impl.add(4, 5); verify(dao).save(any(CalculationResult.class)); } @ankarajug #testinfected
  • 51. Anatomy of a Mock Test @Test public void addInvokedSuccessfully() { when(helper.retrieveSomeStuff()). thenReturn(someNiceInstance); impl.add(4, 5); verify(dao).save(any(CalculationResult.class)); } @ankarajug #testinfected
  • 52. Anatomy of a Mock Test Always use static imports while using Matchers... Also see other annotations, @Spy @Captor little something something on the topic: http://www.jroller.com/mert/entry/anatomy_of_a_mock_test @ankarajug #testinfected
  • 53. Functional Testing Enough with coding..! let’s see that it just works.. mode on... UI Testing with Selenium with the IDE Web Service Testing with SoapUI Functional Testing Load Testing jMeter Performance Testing @ankarajug #testinfected
  • 54. Code Walkthrough Mock Testing Functional Testing (SoapUI, jMeter, Selenium) @ankarajug #testinfected
  • 55. Continuous Integration leads to Continuous Delivery So you have 10.000 tests... Congratz..! But... They’ll be useless if developers need to run them by hand every time..! We need a build triggered with each commit, right? @ankarajug #testinfected
  • 56. Continuous Integration Tools out in the field Hudson Jenkins @ankarajug #testinfected
  • 57. Release Life Cycle Demystified Pre-Alpha } Release } Candidate General Alpha Availability (GA) Release to Manufacturing (RTM) Beta @ankarajug #testinfected
  • 58. Release Life Cycle Pre-Alpha More of an idea in development... with nightly builds..milestones.. testing phase ox eB x Working draft but probably w/ lots W k hit Bo Alpha lac Box of bugs...do extensive testing on it...! B ey feature freeze Gr The prototype..features are complete..! Beta first time available to the outsiders (open/closed beta) The radiation level is high..! but not relevant of course, since these are the first 2 letters of greek alphabet.. @ankarajug #testinfected
  • 59. Release Life Cycle code complete Release all features implemented/tested Candidate call for a “code complete". you have the candidate..! ready to release Release to You are ready to go mass manufacturing. Manufacturing hardware + software bundled together. (RTM) ready to advertise General You are now live..! you did all the commercial Availability (GA) stuff and you are good to go.. just sell it..!!! @ankarajug #testinfected
  • 60. Continuous Integration DEMO w/ Jenkins @ankarajug #testinfected
  • 61. Continuous Inspection Metric dashboard for, Test & Code Coverage (cobertura) Coding Violations (checkstyle) Triggering at each build so you’ll have incremental reports. For installation and getting it up and running you need to, configure its DB, hook it with Jenkins to make more sense... @ankarajug #testinfected
  • 62. Continuous Inspection DEMO w/ Sonar @ankarajug #testinfected
  • 63. Continuous Integration and Inspection DEMO with BAMBOO and CLOVER Kerem ÇAĞLAR Solveka Yazılım @ankarajug #testinfected
  • 64. Best Practices Use Matchers with static imports... Assert.assertEquals(result.getResult().doubleValue(), 9.0); assertThat(result.getResult(), is(9.0)); Test method names can be long, no worries. They should be understood when read by someone like, retrieveListStatusByNationalIdReturnsOneElementWh enThereIsManuallyAddedPersonWithExemptedInfo() @ankarajug #testinfected
  • 65. Some Whenever you are tempted to type something into a print statement or a debugger expression, write it as a test instead (Martin Fowler) Code without automated test simply doesn’t exist. Once you get them running, make sure they stay running. If you can’t test it, just trash it. @ankarajug #testinfected
  • 66. Some We do not need private methods, get rid of them..! Run the fast tests first.. group them.. If they fail you’ll get notified early. Test your app with different localizations (for sorting and etc.) Increase your coverage for sleeping tight at night. Keep the bar green to keep the code clean. You want to test the code, not yourself. Don’t be the keyboard monkey... @ankarajug #testinfected
  • 67. You cannot test EVERYTHING..! @ankarajug #testinfected