SlideShare uma empresa Scribd logo
1 de 43
Hurdle run through EJB testing

Jakub www.marchwicki.pl / @kubem
This is not only about testing

        Neither about EJB
             Nor TDD
   Just somewhere in between
WHO IS THIS GUY?!
Business intelligence and data modelling
          Inteligent marketing
               Data mining

     I’m part of Automotive Group
    Working on Operation Data Store
   Realtime view for Data Warehouse
So let’s start with EJB

      Is it a a plane?
         Is it a bird?
    Is it a framework?
JEE takes all these technologies

           Puts it together
          In a single server
              Big server
 And we are enterprise (from now on)
According to the spec

  You are now about to
         Develop
        Assemble
         Deploy
           Run
  an Enterprise Solution
Emmm…

- Are we testing anything here, sir?
 - Nah… Test are for testers, n00b!
TDD

It’s a Tester Driven Development
          … bitch please!
But seriously – Test Pyramid
Tests…?

                   But tests slows me down
                   They need maintenance
                   This is too simple to test
            And I don’t make mistakes afterall
           This is legacy code, there are no tests
                Build takes time… more time




http://www.slideshare.net/sebrose/common-objections-to-tdd-and-their-refutations
Start from the bottom

          Unit tests don’t:
        talk to the database
     communicate over network
        touch the file system
    need to be run independently
          (tests can run simultaneously)

need special environment configuration
No tests in EJB?

If these are integretion tests…
           It means…
   There are no tests in EJB…
            Woohoo!
           Quick win!
Ekhmmm…

 Is EJB the only framework?
How do other tackle testing?
You know when it’s Spring

Rod Johnson says it’s all about testing
Dependency Injection


@ContextConfiguration
@RunWith(SpringJUnit4ClassRunner.class)
public class ExampleConfigurationTests {
    @Autowired
    ApplicationContext ctx;

    @Autowired
    MyService service;

    @Test
    public void servletTest() throws Exception {

        //.. yada yada
    }

}
Database tests



<beans>
    <jdbc:embedded-database id="dataSource" type="HSQL">
         <jdbc:script location="import.sql"/>
    </jdbc:embedded-database>
</beans>
Spring + Web
@Autowired
ApplicationContext ctx;

@Autowired
TaskController controller;

@Test
public void servletTest() throws Exception {
   MockHttpServletRequest req = new MockHttpServletRequest("GET", "/tasks");
   MockHttpServletResponse resp = new MockHttpServletResponse();
   HandlerAdapter handlerAdapter =
    ctx.getBean(AnnotationMethodHandlerAdapter.class);
   final ModelAndView model = handlerAdapter.handle(req, resp, controller);

    assertViewName(model, "tasks");
    assertAndReturnModelAttributeOfType(model, "task", Task.class);
    assertAndReturnModelAttributeOfType(model, "tasks", List.class);

    //.. create testTask object

    assertModelAttributeValue(model, "tasks", Arrays.asList(testTask));
    assertModelAttributeValue(model, "task", new Task());
}
Spring + Web (2)

MockMvcBuilders.annotationConfigSetup(TestConfiguration.class)
    .build()
    .perform(get("/resources/Spring.js"))
    .andExpect(content().type("application/octet-stream"))
    .andExpect(content().string(containsString("Spring={};")));
RestEASY
MockHttpRequest request = MockHttpRequest.get("/user/1234");
MockHttpResponse response = new MockHttpResponse();

Dispatcher dispatcher = MockDispatcherFactory.createDispatcher();
dispatcher.invoke(request, response);
assertEquals(response.getStatus(), HttpServletResponse.SC_METHOD_NOT_ALLOWED);


URI uri = UriBuilder.fromPath("/user/{arg1}/delete").build(clientId);

MockHttpRequest request = MockHttpRequest.get(uri.toString());
MockHttpResponse response = new MockHttpResponse();

dispatcher.invoke(request, response);
assertEquals(response.getStatus(), HttpServletResponse.SC_OK);
assertTrue(response.getContentAsString().contains("def"),
    "Response should contain 'def' result.");
assertTrue(response.getContentAsString().contains("xx"),
    "Response should contain 'xx' result.");
assertTrue(response.getContentAsString().contains("123"),
    "Response should contain '123' result.");
There are frameworks…

           … and frameworks
Some things are built with testing in mind
But we are to talk about EJB

    … available since 2006 (EJB 3.0)

      Vendors deliver a platform
And they don’t really care about testing
     Just until now… 6 f**kn years
           EJB 3.1 is also live
     Still noone cares about tests
                (nearly noone)
Back to The Pyramid
Let’s have a look

             Welcome the sample application




https://github.com/kubamarchwicki/geecon-ejbtest-workshop
Mate! It’s IDE time!
Mocks are tactical
Fully blown integration

There is a hassle with maintaing DI
   Hello… calling dr. Container
       It’s your job afterall
Are there other options?

     Embed a container
 bootsrtap whole application
        test end2end
Mate! It’s IDE time!
What’s else - Open EJB


yet another embedded container
What’s else - Open EJB

             PROS
        It just works!
Selective classpath scanning!
What’s else - Open EJB

                  PROS
             It just works!
     Selective classpath scanning!



                 CONS
Different than your production container
What’s else (2) - Arquillian

   wooow, so there is a test framework for EJB
What’s else (2) - Arquillian

                  PROS
Closer to actual production environment
 Independent from the actual container
What’s else (2) - Arquillian

                  PROS
Closer to actual production environment
 Independent from the actual container



                 CONS
           Just graduated
Our container’s adapter is still in alpha
Arquillian seems nice

      Manage lifecycle for you
      Shrinkwrap creates an archive
Adapters link between any container and arquillian
 Remote testing / embedded testing
Mate! It’s IDE time!
Jakub www.marchwicki.pl
       @kubem

Mais conteúdo relacionado

Mais procurados

Unit testing legacy code
Unit testing legacy codeUnit testing legacy code
Unit testing legacy codeLars Thorup
 
Unit Test + Functional Programming = Love
Unit Test + Functional Programming = LoveUnit Test + Functional Programming = Love
Unit Test + Functional Programming = LoveAlvaro Videla
 
Working With Legacy Code
Working With Legacy CodeWorking With Legacy Code
Working With Legacy CodeAndrea Polci
 
Unit Testing your React / Redux app (@BucharestJS)
Unit Testing your React / Redux app (@BucharestJS)Unit Testing your React / Redux app (@BucharestJS)
Unit Testing your React / Redux app (@BucharestJS)Alin Pandichi
 
DotNet unit testing training
DotNet unit testing trainingDotNet unit testing training
DotNet unit testing trainingTom Tang
 
Efficient JavaScript Unit Testing, May 2012
Efficient JavaScript Unit Testing, May 2012Efficient JavaScript Unit Testing, May 2012
Efficient JavaScript Unit Testing, May 2012Hazem Saleh
 
Php unit for drupal 8
Php unit for drupal 8Php unit for drupal 8
Php unit for drupal 8valuebound
 
3 WAYS TO TEST YOUR COLDFUSION API
3 WAYS TO TEST YOUR COLDFUSION API3 WAYS TO TEST YOUR COLDFUSION API
3 WAYS TO TEST YOUR COLDFUSION APIGavin Pickin
 
Mutation Testing
Mutation TestingMutation Testing
Mutation TestingESUG
 
Test driven development and unit testing with examples in C++
Test driven development and unit testing with examples in C++Test driven development and unit testing with examples in C++
Test driven development and unit testing with examples in C++Hong Le Van
 
Test all the things! Automated testing with Drupal 8
Test all the things! Automated testing with Drupal 8Test all the things! Automated testing with Drupal 8
Test all the things! Automated testing with Drupal 8Sam Becker
 
Getting Unstuck: Working with Legacy Code and Data
Getting Unstuck: Working with Legacy Code and DataGetting Unstuck: Working with Legacy Code and Data
Getting Unstuck: Working with Legacy Code and DataCory Foy
 
Jellyfish, JSCONF 2011
Jellyfish, JSCONF 2011Jellyfish, JSCONF 2011
Jellyfish, JSCONF 2011Adam Christian
 
Testing React Applications
Testing React ApplicationsTesting React Applications
Testing React Applicationsstbaechler
 
Writing useful automated tests for the single page applications you build
Writing useful automated tests for the single page applications you buildWriting useful automated tests for the single page applications you build
Writing useful automated tests for the single page applications you buildAndrei Sebastian Cîmpean
 

Mais procurados (20)

Test driving-qml
Test driving-qmlTest driving-qml
Test driving-qml
 
Unit testing legacy code
Unit testing legacy codeUnit testing legacy code
Unit testing legacy code
 
Working Effectively with Legacy Code
Working Effectively with Legacy CodeWorking Effectively with Legacy Code
Working Effectively with Legacy Code
 
Unit Test + Functional Programming = Love
Unit Test + Functional Programming = LoveUnit Test + Functional Programming = Love
Unit Test + Functional Programming = Love
 
Working With Legacy Code
Working With Legacy CodeWorking With Legacy Code
Working With Legacy Code
 
Unit Testing your React / Redux app (@BucharestJS)
Unit Testing your React / Redux app (@BucharestJS)Unit Testing your React / Redux app (@BucharestJS)
Unit Testing your React / Redux app (@BucharestJS)
 
DotNet unit testing training
DotNet unit testing trainingDotNet unit testing training
DotNet unit testing training
 
Efficient JavaScript Unit Testing, May 2012
Efficient JavaScript Unit Testing, May 2012Efficient JavaScript Unit Testing, May 2012
Efficient JavaScript Unit Testing, May 2012
 
Unit testing with java
Unit testing with javaUnit testing with java
Unit testing with java
 
Php unit for drupal 8
Php unit for drupal 8Php unit for drupal 8
Php unit for drupal 8
 
Test driving QML
Test driving QMLTest driving QML
Test driving QML
 
3 WAYS TO TEST YOUR COLDFUSION API
3 WAYS TO TEST YOUR COLDFUSION API3 WAYS TO TEST YOUR COLDFUSION API
3 WAYS TO TEST YOUR COLDFUSION API
 
Mutation Testing
Mutation TestingMutation Testing
Mutation Testing
 
Test driven development and unit testing with examples in C++
Test driven development and unit testing with examples in C++Test driven development and unit testing with examples in C++
Test driven development and unit testing with examples in C++
 
Test all the things! Automated testing with Drupal 8
Test all the things! Automated testing with Drupal 8Test all the things! Automated testing with Drupal 8
Test all the things! Automated testing with Drupal 8
 
Getting Unstuck: Working with Legacy Code and Data
Getting Unstuck: Working with Legacy Code and DataGetting Unstuck: Working with Legacy Code and Data
Getting Unstuck: Working with Legacy Code and Data
 
Jellyfish, JSCONF 2011
Jellyfish, JSCONF 2011Jellyfish, JSCONF 2011
Jellyfish, JSCONF 2011
 
Testing React Applications
Testing React ApplicationsTesting React Applications
Testing React Applications
 
Writing useful automated tests for the single page applications you build
Writing useful automated tests for the single page applications you buildWriting useful automated tests for the single page applications you build
Writing useful automated tests for the single page applications you build
 
JavaScript Unit Testing
JavaScript Unit TestingJavaScript Unit Testing
JavaScript Unit Testing
 

Semelhante a GeeCON 2012 hurdle run through ejb testing

Building JBoss AS 7 for Fedora
Building JBoss AS 7 for FedoraBuilding JBoss AS 7 for Fedora
Building JBoss AS 7 for Fedorawolfc71
 
Whitebox testing of Spring Boot applications
Whitebox testing of Spring Boot applicationsWhitebox testing of Spring Boot applications
Whitebox testing of Spring Boot applicationsYura Nosenko
 
In Memory Unit Testing with Apache DbUnit
In Memory Unit Testing with Apache DbUnitIn Memory Unit Testing with Apache DbUnit
In Memory Unit Testing with Apache DbUnitMohammad Sabir Khan
 
軟體測試是在測試什麼?
軟體測試是在測試什麼?軟體測試是在測試什麼?
軟體測試是在測試什麼?Yao Nien Chung
 
Throwing complexity over the wall: Rapid development for enterprise Java (Jav...
Throwing complexity over the wall: Rapid development for enterprise Java (Jav...Throwing complexity over the wall: Rapid development for enterprise Java (Jav...
Throwing complexity over the wall: Rapid development for enterprise Java (Jav...Dan Allen
 
Lessons Learned in Software Development: QA Infrastructure – Maintaining Rob...
Lessons Learned in Software Development: QA Infrastructure – Maintaining Rob...Lessons Learned in Software Development: QA Infrastructure – Maintaining Rob...
Lessons Learned in Software Development: QA Infrastructure – Maintaining Rob...Cωνσtantίnoς Giannoulis
 
EJB 3.0 Java Persistence with Oracle TopLink
EJB 3.0 Java Persistence with Oracle TopLinkEJB 3.0 Java Persistence with Oracle TopLink
EJB 3.0 Java Persistence with Oracle TopLinkBill Lyons
 
OpenDaylight Developer Experience 2.0
 OpenDaylight Developer Experience 2.0 OpenDaylight Developer Experience 2.0
OpenDaylight Developer Experience 2.0Michael Vorburger
 
Ten Man-Years of JavaFX: Real World Project Experiences
Ten Man-Years of JavaFX: Real World Project ExperiencesTen Man-Years of JavaFX: Real World Project Experiences
Ten Man-Years of JavaFX: Real World Project ExperiencesHenrik Olsson
 
The Many Ways to Test Your React App
The Many Ways to Test Your React AppThe Many Ways to Test Your React App
The Many Ways to Test Your React AppAll Things Open
 
Testing Vue Apps with Cypress.io (STLJS Meetup April 2018)
Testing Vue Apps with Cypress.io (STLJS Meetup April 2018)Testing Vue Apps with Cypress.io (STLJS Meetup April 2018)
Testing Vue Apps with Cypress.io (STLJS Meetup April 2018)Christian Catalan
 
TDD super mondays-june-2014
TDD super mondays-june-2014TDD super mondays-june-2014
TDD super mondays-june-2014Alex Kavanagh
 
Agile JavaScript Testing
Agile JavaScript TestingAgile JavaScript Testing
Agile JavaScript TestingScott Becker
 
TDD in the Web with Python and Django
TDD in the Web with Python and DjangoTDD in the Web with Python and Django
TDD in the Web with Python and DjangoCarlos Ble
 
Effective Test Driven Database Development
Effective Test Driven Database DevelopmentEffective Test Driven Database Development
Effective Test Driven Database Developmentelliando dias
 

Semelhante a GeeCON 2012 hurdle run through ejb testing (20)

Building JBoss AS 7 for Fedora
Building JBoss AS 7 for FedoraBuilding JBoss AS 7 for Fedora
Building JBoss AS 7 for Fedora
 
Whitebox testing of Spring Boot applications
Whitebox testing of Spring Boot applicationsWhitebox testing of Spring Boot applications
Whitebox testing of Spring Boot applications
 
In Memory Unit Testing with Apache DbUnit
In Memory Unit Testing with Apache DbUnitIn Memory Unit Testing with Apache DbUnit
In Memory Unit Testing with Apache DbUnit
 
Sadiq786
Sadiq786Sadiq786
Sadiq786
 
軟體測試是在測試什麼?
軟體測試是在測試什麼?軟體測試是在測試什麼?
軟體測試是在測試什麼?
 
Throwing complexity over the wall: Rapid development for enterprise Java (Jav...
Throwing complexity over the wall: Rapid development for enterprise Java (Jav...Throwing complexity over the wall: Rapid development for enterprise Java (Jav...
Throwing complexity over the wall: Rapid development for enterprise Java (Jav...
 
Tdd vs SQL
Tdd vs SQLTdd vs SQL
Tdd vs SQL
 
Lessons Learned in Software Development: QA Infrastructure – Maintaining Rob...
Lessons Learned in Software Development: QA Infrastructure – Maintaining Rob...Lessons Learned in Software Development: QA Infrastructure – Maintaining Rob...
Lessons Learned in Software Development: QA Infrastructure – Maintaining Rob...
 
EJB 3.0 Java Persistence with Oracle TopLink
EJB 3.0 Java Persistence with Oracle TopLinkEJB 3.0 Java Persistence with Oracle TopLink
EJB 3.0 Java Persistence with Oracle TopLink
 
OpenDaylight Developer Experience 2.0
 OpenDaylight Developer Experience 2.0 OpenDaylight Developer Experience 2.0
OpenDaylight Developer Experience 2.0
 
Ten Man-Years of JavaFX: Real World Project Experiences
Ten Man-Years of JavaFX: Real World Project ExperiencesTen Man-Years of JavaFX: Real World Project Experiences
Ten Man-Years of JavaFX: Real World Project Experiences
 
The Many Ways to Test Your React App
The Many Ways to Test Your React AppThe Many Ways to Test Your React App
The Many Ways to Test Your React App
 
Js tacktalk team dev js testing performance
Js tacktalk team dev js testing performanceJs tacktalk team dev js testing performance
Js tacktalk team dev js testing performance
 
Testing Vue Apps with Cypress.io (STLJS Meetup April 2018)
Testing Vue Apps with Cypress.io (STLJS Meetup April 2018)Testing Vue Apps with Cypress.io (STLJS Meetup April 2018)
Testing Vue Apps with Cypress.io (STLJS Meetup April 2018)
 
TDD super mondays-june-2014
TDD super mondays-june-2014TDD super mondays-june-2014
TDD super mondays-june-2014
 
Agile JavaScript Testing
Agile JavaScript TestingAgile JavaScript Testing
Agile JavaScript Testing
 
TDD in the Web with Python and Django
TDD in the Web with Python and DjangoTDD in the Web with Python and Django
TDD in the Web with Python and Django
 
Effective Test Driven Database Development
Effective Test Driven Database DevelopmentEffective Test Driven Database Development
Effective Test Driven Database Development
 
Integration testing - A&BP CC
Integration testing - A&BP CCIntegration testing - A&BP CC
Integration testing - A&BP CC
 
Gallio Crafting A Toolchain
Gallio Crafting A ToolchainGallio Crafting A Toolchain
Gallio Crafting A Toolchain
 

Mais de Jakub Marchwicki

Test with Spock like the first officer
Test with Spock like the first officerTest with Spock like the first officer
Test with Spock like the first officerJakub Marchwicki
 
Design principles 4 hackers - tech3camp (28142014)
Design principles 4 hackers - tech3camp (28142014)Design principles 4 hackers - tech3camp (28142014)
Design principles 4 hackers - tech3camp (28142014)Jakub Marchwicki
 
[PL] Jak programować aby nie zwariować
[PL] Jak programować aby nie zwariować[PL] Jak programować aby nie zwariować
[PL] Jak programować aby nie zwariowaćJakub Marchwicki
 
GeeCON 2013 - EJB application guided by tests
GeeCON 2013 - EJB application guided by testsGeeCON 2013 - EJB application guided by tests
GeeCON 2013 - EJB application guided by testsJakub Marchwicki
 
[PL] Jak programować aby nie zwariować?
[PL] Jak programować aby nie zwariować?[PL] Jak programować aby nie zwariować?
[PL] Jak programować aby nie zwariować?Jakub Marchwicki
 
[PL] Metadane - dane o danych
[PL] Metadane - dane o danych[PL] Metadane - dane o danych
[PL] Metadane - dane o danychJakub Marchwicki
 
[PL] O klasycznej, programistycznej elegancji
[PL] O klasycznej, programistycznej elegancji[PL] O klasycznej, programistycznej elegancji
[PL] O klasycznej, programistycznej elegancjiJakub Marchwicki
 

Mais de Jakub Marchwicki (8)

Test with Spock like the first officer
Test with Spock like the first officerTest with Spock like the first officer
Test with Spock like the first officer
 
Design principles 4 hackers - tech3camp (28142014)
Design principles 4 hackers - tech3camp (28142014)Design principles 4 hackers - tech3camp (28142014)
Design principles 4 hackers - tech3camp (28142014)
 
JEE.next()
JEE.next()JEE.next()
JEE.next()
 
[PL] Jak programować aby nie zwariować
[PL] Jak programować aby nie zwariować[PL] Jak programować aby nie zwariować
[PL] Jak programować aby nie zwariować
 
GeeCON 2013 - EJB application guided by tests
GeeCON 2013 - EJB application guided by testsGeeCON 2013 - EJB application guided by tests
GeeCON 2013 - EJB application guided by tests
 
[PL] Jak programować aby nie zwariować?
[PL] Jak programować aby nie zwariować?[PL] Jak programować aby nie zwariować?
[PL] Jak programować aby nie zwariować?
 
[PL] Metadane - dane o danych
[PL] Metadane - dane o danych[PL] Metadane - dane o danych
[PL] Metadane - dane o danych
 
[PL] O klasycznej, programistycznej elegancji
[PL] O klasycznej, programistycznej elegancji[PL] O klasycznej, programistycznej elegancji
[PL] O klasycznej, programistycznej elegancji
 

Último

"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfRankYa
 
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfHyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfPrecisely
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteDianaGray10
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .Alan Dix
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionDilum Bandara
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxhariprasad279825
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piececharlottematthew16
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsMiki Katsuragi
 

Último (20)

"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdf
 
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfHyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test Suite
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An Introduction
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptx
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piece
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering Tips
 

GeeCON 2012 hurdle run through ejb testing

  • 1. Hurdle run through EJB testing Jakub www.marchwicki.pl / @kubem
  • 2. This is not only about testing Neither about EJB Nor TDD Just somewhere in between
  • 3. WHO IS THIS GUY?!
  • 4. Business intelligence and data modelling Inteligent marketing Data mining I’m part of Automotive Group Working on Operation Data Store Realtime view for Data Warehouse
  • 5. So let’s start with EJB Is it a a plane? Is it a bird? Is it a framework?
  • 6. JEE takes all these technologies Puts it together In a single server Big server And we are enterprise (from now on)
  • 7. According to the spec You are now about to Develop Assemble Deploy Run an Enterprise Solution
  • 8. Emmm… - Are we testing anything here, sir? - Nah… Test are for testers, n00b!
  • 9. TDD It’s a Tester Driven Development … bitch please!
  • 10.
  • 11.
  • 12. But seriously – Test Pyramid
  • 13. Tests…? But tests slows me down They need maintenance This is too simple to test And I don’t make mistakes afterall This is legacy code, there are no tests Build takes time… more time http://www.slideshare.net/sebrose/common-objections-to-tdd-and-their-refutations
  • 14.
  • 15. Start from the bottom Unit tests don’t: talk to the database communicate over network touch the file system need to be run independently (tests can run simultaneously) need special environment configuration
  • 16. No tests in EJB? If these are integretion tests… It means… There are no tests in EJB… Woohoo! Quick win!
  • 17. Ekhmmm… Is EJB the only framework? How do other tackle testing?
  • 18.
  • 19. You know when it’s Spring Rod Johnson says it’s all about testing
  • 20. Dependency Injection @ContextConfiguration @RunWith(SpringJUnit4ClassRunner.class) public class ExampleConfigurationTests { @Autowired ApplicationContext ctx; @Autowired MyService service; @Test public void servletTest() throws Exception { //.. yada yada } }
  • 21. Database tests <beans> <jdbc:embedded-database id="dataSource" type="HSQL"> <jdbc:script location="import.sql"/> </jdbc:embedded-database> </beans>
  • 22. Spring + Web @Autowired ApplicationContext ctx; @Autowired TaskController controller; @Test public void servletTest() throws Exception { MockHttpServletRequest req = new MockHttpServletRequest("GET", "/tasks"); MockHttpServletResponse resp = new MockHttpServletResponse(); HandlerAdapter handlerAdapter = ctx.getBean(AnnotationMethodHandlerAdapter.class); final ModelAndView model = handlerAdapter.handle(req, resp, controller); assertViewName(model, "tasks"); assertAndReturnModelAttributeOfType(model, "task", Task.class); assertAndReturnModelAttributeOfType(model, "tasks", List.class); //.. create testTask object assertModelAttributeValue(model, "tasks", Arrays.asList(testTask)); assertModelAttributeValue(model, "task", new Task()); }
  • 23. Spring + Web (2) MockMvcBuilders.annotationConfigSetup(TestConfiguration.class) .build() .perform(get("/resources/Spring.js")) .andExpect(content().type("application/octet-stream")) .andExpect(content().string(containsString("Spring={};")));
  • 24. RestEASY MockHttpRequest request = MockHttpRequest.get("/user/1234"); MockHttpResponse response = new MockHttpResponse(); Dispatcher dispatcher = MockDispatcherFactory.createDispatcher(); dispatcher.invoke(request, response); assertEquals(response.getStatus(), HttpServletResponse.SC_METHOD_NOT_ALLOWED); URI uri = UriBuilder.fromPath("/user/{arg1}/delete").build(clientId); MockHttpRequest request = MockHttpRequest.get(uri.toString()); MockHttpResponse response = new MockHttpResponse(); dispatcher.invoke(request, response); assertEquals(response.getStatus(), HttpServletResponse.SC_OK); assertTrue(response.getContentAsString().contains("def"), "Response should contain 'def' result."); assertTrue(response.getContentAsString().contains("xx"), "Response should contain 'xx' result."); assertTrue(response.getContentAsString().contains("123"), "Response should contain '123' result.");
  • 25. There are frameworks… … and frameworks Some things are built with testing in mind
  • 26. But we are to talk about EJB … available since 2006 (EJB 3.0) Vendors deliver a platform And they don’t really care about testing Just until now… 6 f**kn years EJB 3.1 is also live Still noone cares about tests (nearly noone)
  • 27. Back to The Pyramid
  • 28. Let’s have a look Welcome the sample application https://github.com/kubamarchwicki/geecon-ejbtest-workshop
  • 31. Fully blown integration There is a hassle with maintaing DI Hello… calling dr. Container It’s your job afterall
  • 32. Are there other options? Embed a container bootsrtap whole application test end2end
  • 34.
  • 35. What’s else - Open EJB yet another embedded container
  • 36. What’s else - Open EJB PROS It just works! Selective classpath scanning!
  • 37. What’s else - Open EJB PROS It just works! Selective classpath scanning! CONS Different than your production container
  • 38. What’s else (2) - Arquillian wooow, so there is a test framework for EJB
  • 39. What’s else (2) - Arquillian PROS Closer to actual production environment Independent from the actual container
  • 40. What’s else (2) - Arquillian PROS Closer to actual production environment Independent from the actual container CONS Just graduated Our container’s adapter is still in alpha
  • 41. Arquillian seems nice Manage lifecycle for you Shrinkwrap creates an archive Adapters link between any container and arquillian Remote testing / embedded testing