SlideShare a Scribd company logo
TESTE DE INTEGRAÇÃO




              jIntegrity

           WASHINGTON BOTELHO



@wbotelhos | wbotelhos.com.br | #CafeComJava
Por que testar?
Por que testar?



Para garantir o funcionamento do código.
Quais o tipos comuns de teste?
Quais o tipos comuns de teste?




Unidade
Quais o tipos comuns de teste?




Unidade                    Manual
Quais o tipos comuns de teste?




Unidade                    Manual



            Aceitação
Quais o tipos comuns de teste?


            Integração

Unidade                    Manual



            Aceitação
Teste de integração é
  teste de “maxu”.
Eu disse Macho!!!
Acessa diretamente o
  banco de dados
Terei que alimentar o banco?
@Before
public void setup() {
  // SQL code...
}




                        @After
                        public void tearDown() {
                          // SQL code...
                        }
@Before
public void setup() {
  // SQL code...
}




@Test
public void shouldLoadByID() {
	 assertNotNull("should find", repository.loadByID(1l));
}




                                  @After
                                  public void tearDown() {
                                    // SQL code...
                                  }
Model x XML

              public class User {

                private Long id;
              	 private String email;
              	 private String name;

              }




<dataset>
	 <User id="1" email="email-1@mail.com" name="name-1" />
	 <User id="2" email="email-2@mail.com" name="name-2" />
	 <User id="3" email="email-3@mail.com" name="name-3" />
</dataset>
@Before
public void setup() {
	 execute(INSERT, "User.xml");
}




@Test
public void shouldLoadByID() {
	 assertNotNull("should find", repository.loadByID(1l));
}




                                 @After
                                 public void tearDown() {
                                   execute(DELETE, "User.xml");
                                 }
Dump     Insert




Delete   Update
Dump               Insert

         Restore




          XML

Delete             Update
Class.forName("com.mysql.jdbc.Driver").newInstance();

Connection conn = DriverManager
   .getConnection("jdbc:mysql://localhost/test", "root", "root");
Class.forName("com.mysql.jdbc.Driver").newInstance();

Connection conn = DriverManager
   .getConnection("jdbc:mysql://localhost/test", "root", "root");



IDatabaseConnection iConn = new DatabaseConnection(conn);
Class.forName("com.mysql.jdbc.Driver").newInstance();

Connection conn = DriverManager
   .getConnection("jdbc:mysql://localhost/test", "root", "root");



IDatabaseConnection iConn = new DatabaseConnection(conn);



InputStream stream = getClass().getResourceAsStream("/User.xml");

FlatXmlDataSetBuilder builder = new FlatXmlDataSetBuilder();

IDataSet dataSet = builder.build(stream);
Class.forName("com.mysql.jdbc.Driver").newInstance();

Connection conn = DriverManager
   .getConnection("jdbc:mysql://localhost/test", "root", "root");



IDatabaseConnection iConn = new DatabaseConnection(conn);



InputStream stream = getClass().getResourceAsStream("/User.xml");

FlatXmlDataSetBuilder builder = new FlatXmlDataSetBuilder();

IDataSet dataSet = builder.build(stream);



DatabaseOperation.INSERT.execute(iConn, dataSet);

iConn.close();
execute(INSERT, xml);



                           execute(DELETE_ALL, xml);



execute(REFRESH, xml);



                          execute(CLEAN_INSERT, xml);



execute(UPDATE, xml);



                         execute(TRUNCATE_TABLE, xml);


execute(DELETE, xml);
Show me the code!
Problemas

  Muito código?                             Organização?


dbUnitProvider.execute(DatabaseOperation.INSERT, "/User.xml");
dbUnitProvider.execute(DatabaseOperation.INSERT, "/Product.xml");
dbUnitProvider.execute(DatabaseOperation.INSERT, "/Payment.xml");




dbUnitProvider.execute(DatabaseOperation.DELETE, "/Payment.xml");
dbUnitProvider.execute(DatabaseOperation.DELETE, "/Product.xml");
dbUnitProvider.execute(DatabaseOperation.DELETE, "/User.xml");



   Flexibilidade?                             Reescrita?
jIntegrity
A toolbox to help you test!
Properties
jintegrity.properties

              path=
              xml=User,Product,Payment




     "/User.xml", "/Product.xml", "/Payment.xml"
Properties
jintegrity.properties

              path=
              xml=User,Product,Payment




     "/User.xml", "/Product.xml", "/Payment.xml"



hibernate.properties

         hibernate.connection.driver_class=
         hibernate.connection.url=
         hibernate.connection.username=
         hibernate.connection.password=
Configuração transparente!


   JIntegrity helper = new JIntegrity();
helper.insert();




helper.clean();
helper.insert();




  "/User.xml", "/Product.xml", "/Payment.xml"




helper.clean();
helper.insert();




  "/User.xml", "/Product.xml", "/Payment.xml"




helper.clean();




  "/Payment.xml", "/Product.xml", "/User.xml" // self.down?
helper.insert();




  "/User.xml", "/Product.xml", "/Payment.xml"




                               helper.cleanAndInsert();

helper.clean();




  "/Payment.xml", "/Product.xml", "/User.xml" // self.down?
Flexibilidade!

helper.path("my/package/dataset").insert();
Flexibilidade!

helper.path("my/package/dataset").insert();




helper.xml("User", "Payment").insert();
Flexibilidade!

   helper.path("my/package/dataset").insert();




   helper.xml("User", "Payment").insert();




helper
.insert()
  .insert("User")
    .path("package/dataset").xml("User").insert()
       .insert("/package/xml/User");
Vendors!

helper.vendor(JIntegrity.ORACLE10G);
Vendors!

helper.vendor(JIntegrity.ORACLE10G);




helper.useDB2();
helper.useHSQL();
helper.useMSSQL();
helper.useMySQL();
helper.useOracle10g();
Helpers!
Helpers!
private UserRepository repository;
Helpers!
private UserRepository repository;



@BeforeClass public static void beforeClass() {
   JPAHelper.entityManagerFactory("default");
}
Helpers!
private UserRepository repository;



@BeforeClass public static void beforeClass() {
   JPAHelper.entityManagerFactory("default");
}	



@Before public void setup() {
   EntityManager manager = JPAHelper.currentEntityManager();
   repository = new UserBusiness(manager);
}
Helpers!
private UserRepository repository;



@BeforeClass public static void beforeClass() {
   JPAHelper.entityManagerFactory("default");
}	



@Before public void setup() {
   EntityManager manager = JPAHelper.currentEntityManager();
   repository = new UserBusiness(manager);
}



@After public void tearDown() {
  JPAHelper.close();
}
Show me the code!
#greenbar
Referências


         DbUnit.org

      jIntegrity.com


github.com/wbotelhos/jintegrity
Dúvidas?
Obrigado! (:




      jIntegrity

   WASHINGTON BOTELHO



@wbotelhos | wbotelhos.com.br

More Related Content

PDF
Devoxx 15 equals hashcode
PDF
Selectors and normalizing state shape
PPTX
Sequelize
KEY
SOLID Principles
PPT
Testing persistence in PHP with DbUnit
PPTX
Jdk(java) 7 - 6 기타기능
PDF
Hidden Treasures of the Python Standard Library
PDF
#36.스프링프레임워크 & 마이바티스 (Spring Framework, MyBatis)_재직자환급교육,실업자교육,국비지원교육, 자바교육,구...
Devoxx 15 equals hashcode
Selectors and normalizing state shape
Sequelize
SOLID Principles
Testing persistence in PHP with DbUnit
Jdk(java) 7 - 6 기타기능
Hidden Treasures of the Python Standard Library
#36.스프링프레임워크 & 마이바티스 (Spring Framework, MyBatis)_재직자환급교육,실업자교육,국비지원교육, 자바교육,구...

What's hot (20)

PDF
Java libraries you can't afford to miss
DOCX
MVest Spring Job Execution
TXT
Excelsheet
PPTX
JDBC - JPA - Spring Data
PDF
Web2py
PDF
Stubる - Mockingjayを使ったHTTPクライアントのテスト -
PDF
How to Design a Great API (using flask) [ploneconf2017]
PDF
Building node.js applications with Database Jones
PDF
History of jQuery
PDF
droidparts
PDF
Lean React - Patterns for High Performance [ploneconf2017]
PPTX
TDD in the wild
PDF
Annotation Processing in Android
PDF
05 JavaScript #burningkeyboards
PDF
Mastering Oracle ADF Bindings
PDF
06 jQuery #burningkeyboards
DOC
Selenium Webdriver with data driven framework
TXT
Conexcion java mysql
PDF
Advanced java practical semester 6_computer science
Java libraries you can't afford to miss
MVest Spring Job Execution
Excelsheet
JDBC - JPA - Spring Data
Web2py
Stubる - Mockingjayを使ったHTTPクライアントのテスト -
How to Design a Great API (using flask) [ploneconf2017]
Building node.js applications with Database Jones
History of jQuery
droidparts
Lean React - Patterns for High Performance [ploneconf2017]
TDD in the wild
Annotation Processing in Android
05 JavaScript #burningkeyboards
Mastering Oracle ADF Bindings
06 jQuery #burningkeyboards
Selenium Webdriver with data driven framework
Conexcion java mysql
Advanced java practical semester 6_computer science
Ad

Similar to Teste de Integração com DbUnit e jIntegrity (20)

KEY
Enterprise Java Web Application Frameworks Sample Stack Implementation
PDF
Using the latest Java Persistence API 2 Features - Tech Days 2010 India
PDF
Understanding
PDF
Using the latest Java Persistence API 2.0 features
PPT
Jpa & hibernate
PDF
Spring data requery
PDF
Evolution of database access technologies in Java-based software projects
PDF
PDF
spring-tutorial
PDF
Powerful persistence layer with Google Guice & MyBatis
PDF
New Features of JSR 317 (JPA 2.0)
PDF
Querydsl fin jug - june 2012
PPTX
Hibernate in XPages
PPT
Hibernate
PDF
Java persistence api 2.1
PDF
Whats New In Java Ee 6
PDF
Apache Con Us2007 Apachei Batis
 
PDF
Java Online Training
PPTX
Codecamp iasi-26 nov 2011-what's new in jpa 2.0
PPTX
Ups and downs of enterprise Java app in a research setting
Enterprise Java Web Application Frameworks Sample Stack Implementation
Using the latest Java Persistence API 2 Features - Tech Days 2010 India
Understanding
Using the latest Java Persistence API 2.0 features
Jpa & hibernate
Spring data requery
Evolution of database access technologies in Java-based software projects
spring-tutorial
Powerful persistence layer with Google Guice & MyBatis
New Features of JSR 317 (JPA 2.0)
Querydsl fin jug - june 2012
Hibernate in XPages
Hibernate
Java persistence api 2.1
Whats New In Java Ee 6
Apache Con Us2007 Apachei Batis
 
Java Online Training
Codecamp iasi-26 nov 2011-what's new in jpa 2.0
Ups and downs of enterprise Java app in a research setting
Ad

Recently uploaded (20)

PDF
NewMind AI Weekly Chronicles - August'25 Week I
PPTX
MYSQL Presentation for SQL database connectivity
PPTX
breach-and-attack-simulation-cybersecurity-india-chennai-defenderrabbit-2025....
PDF
NewMind AI Monthly Chronicles - July 2025
PDF
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PDF
Transforming Manufacturing operations through Intelligent Integrations
PDF
GamePlan Trading System Review: Professional Trader's Honest Take
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PDF
Advanced IT Governance
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PPTX
Understanding_Digital_Forensics_Presentation.pptx
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PDF
AI And Its Effect On The Evolving IT Sector In Australia - Elevate
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PDF
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
NewMind AI Weekly Chronicles - August'25 Week I
MYSQL Presentation for SQL database connectivity
breach-and-attack-simulation-cybersecurity-india-chennai-defenderrabbit-2025....
NewMind AI Monthly Chronicles - July 2025
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
“AI and Expert System Decision Support & Business Intelligence Systems”
Transforming Manufacturing operations through Intelligent Integrations
GamePlan Trading System Review: Professional Trader's Honest Take
Reach Out and Touch Someone: Haptics and Empathic Computing
Advanced IT Governance
Advanced methodologies resolving dimensionality complications for autism neur...
Understanding_Digital_Forensics_Presentation.pptx
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
AI And Its Effect On The Evolving IT Sector In Australia - Elevate
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
Dropbox Q2 2025 Financial Results & Investor Presentation
Diabetes mellitus diagnosis method based random forest with bat algorithm
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...

Teste de Integração com DbUnit e jIntegrity