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çãoUnidade                    Manual            Aceitação
Teste de integração é  teste de “maxu”.
Eu disse Macho!!!
Acessa diretamente o  banco de dados
Terei que alimentar o banco?
@Beforepublic void setup() {  // SQL code...}                        @After                        public void tearDown() ...
@Beforepublic void setup() {  // SQL code...}@Testpublic void shouldLoadByID() {	 assertNotNull("should find", repository....
Model x XML              public class User {                private Long id;              	 private String email;         ...
@Beforepublic void setup() {	 execute(INSERT, "User.xml");}@Testpublic void shouldLoadByID() {	 assertNotNull("should find...
Dump     InsertDelete   Update
Dump               Insert         Restore          XMLDelete             Update
Class.forName("com.mysql.jdbc.Driver").newInstance();Connection conn = DriverManager   .getConnection("jdbc:mysql://localh...
Class.forName("com.mysql.jdbc.Driver").newInstance();Connection conn = DriverManager   .getConnection("jdbc:mysql://localh...
Class.forName("com.mysql.jdbc.Driver").newInstance();Connection conn = DriverManager   .getConnection("jdbc:mysql://localh...
Class.forName("com.mysql.jdbc.Driver").newInstance();Connection conn = DriverManager   .getConnection("jdbc:mysql://localh...
execute(INSERT, xml);                           execute(DELETE_ALL, xml);execute(REFRESH, xml);                          e...
Show me the code!
Problemas  Muito código?                             Organização?dbUnitProvider.execute(DatabaseOperation.INSERT, "/User.x...
jIntegrityA toolbox to help you test!
Propertiesjintegrity.properties              path=              xml=User,Product,Payment     "/User.xml", "/Product.xml", ...
Propertiesjintegrity.properties              path=              xml=User,Product,Payment     "/User.xml", "/Product.xml", ...
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" ...
helper.insert();  "/User.xml", "/Product.xml", "/Payment.xml"                               helper.cleanAndInsert();helper...
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()  .in...
Vendors!helper.vendor(JIntegrity.ORACLE10G);
Vendors!helper.vendor(JIntegrity.ORACLE10G);helper.useDB2();helper.useHSQL();helper.useMSSQL();helper.useMySQL();helper.us...
Helpers!
Helpers!private UserRepository repository;
Helpers!private UserRepository repository;@BeforeClass public static void beforeClass() {   JPAHelper.entityManagerFactory...
Helpers!private UserRepository repository;@BeforeClass public static void beforeClass() {   JPAHelper.entityManagerFactory...
Helpers!private UserRepository repository;@BeforeClass public static void beforeClass() {   JPAHelper.entityManagerFactory...
Show me the code!
#greenbar
Referências         DbUnit.org      jIntegrity.comgithub.com/wbotelhos/jintegrity
Dúvidas?
Obrigado! (:      jIntegrity   WASHINGTON BOTELHO@wbotelhos | wbotelhos.com.br
Upcoming SlideShare
Loading in …5
×

Teste de Integração com DbUnit e jIntegrity

3,149 views

Published on

Teste de Integração com DbUnit e jIntegrity

Published in: Technology, News & Politics
0 Comments
2 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
3,149
On SlideShare
0
From Embeds
0
Number of Embeds
1,320
Actions
Shares
0
Downloads
29
Comments
0
Likes
2
Embeds 0
No embeds

No notes for slide

Teste de Integração com DbUnit e jIntegrity

  1. 1. TESTE DE INTEGRAÇÃO jIntegrity WASHINGTON BOTELHO@wbotelhos | wbotelhos.com.br | #CafeComJava
  2. 2. Por que testar?
  3. 3. Por que testar?Para garantir o funcionamento do código.
  4. 4. Quais o tipos comuns de teste?
  5. 5. Quais o tipos comuns de teste?Unidade
  6. 6. Quais o tipos comuns de teste?Unidade Manual
  7. 7. Quais o tipos comuns de teste?Unidade Manual Aceitação
  8. 8. Quais o tipos comuns de teste? IntegraçãoUnidade Manual Aceitação
  9. 9. Teste de integração é teste de “maxu”.
  10. 10. Eu disse Macho!!!
  11. 11. Acessa diretamente o banco de dados
  12. 12. Terei que alimentar o banco?
  13. 13. @Beforepublic void setup() { // SQL code...} @After public void tearDown() { // SQL code... }
  14. 14. @Beforepublic void setup() { // SQL code...}@Testpublic void shouldLoadByID() { assertNotNull("should find", repository.loadByID(1l));} @After public void tearDown() { // SQL code... }
  15. 15. 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>
  16. 16. @Beforepublic void setup() { execute(INSERT, "User.xml");}@Testpublic void shouldLoadByID() { assertNotNull("should find", repository.loadByID(1l));} @After public void tearDown() { execute(DELETE, "User.xml"); }
  17. 17. Dump InsertDelete Update
  18. 18. Dump Insert Restore XMLDelete Update
  19. 19. Class.forName("com.mysql.jdbc.Driver").newInstance();Connection conn = DriverManager .getConnection("jdbc:mysql://localhost/test", "root", "root");
  20. 20. Class.forName("com.mysql.jdbc.Driver").newInstance();Connection conn = DriverManager .getConnection("jdbc:mysql://localhost/test", "root", "root");IDatabaseConnection iConn = new DatabaseConnection(conn);
  21. 21. 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);
  22. 22. 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();
  23. 23. execute(INSERT, xml); execute(DELETE_ALL, xml);execute(REFRESH, xml); execute(CLEAN_INSERT, xml);execute(UPDATE, xml); execute(TRUNCATE_TABLE, xml);execute(DELETE, xml);
  24. 24. Show me the code!
  25. 25. 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?
  26. 26. jIntegrityA toolbox to help you test!
  27. 27. Propertiesjintegrity.properties path= xml=User,Product,Payment "/User.xml", "/Product.xml", "/Payment.xml"
  28. 28. Propertiesjintegrity.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=
  29. 29. Configuração transparente! JIntegrity helper = new JIntegrity();
  30. 30. helper.insert();helper.clean();
  31. 31. helper.insert(); "/User.xml", "/Product.xml", "/Payment.xml"helper.clean();
  32. 32. helper.insert(); "/User.xml", "/Product.xml", "/Payment.xml"helper.clean(); "/Payment.xml", "/Product.xml", "/User.xml" // self.down?
  33. 33. helper.insert(); "/User.xml", "/Product.xml", "/Payment.xml" helper.cleanAndInsert();helper.clean(); "/Payment.xml", "/Product.xml", "/User.xml" // self.down?
  34. 34. Flexibilidade!helper.path("my/package/dataset").insert();
  35. 35. Flexibilidade!helper.path("my/package/dataset").insert();helper.xml("User", "Payment").insert();
  36. 36. 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");
  37. 37. Vendors!helper.vendor(JIntegrity.ORACLE10G);
  38. 38. Vendors!helper.vendor(JIntegrity.ORACLE10G);helper.useDB2();helper.useHSQL();helper.useMSSQL();helper.useMySQL();helper.useOracle10g();
  39. 39. Helpers!
  40. 40. Helpers!private UserRepository repository;
  41. 41. Helpers!private UserRepository repository;@BeforeClass public static void beforeClass() { JPAHelper.entityManagerFactory("default");}
  42. 42. Helpers!private UserRepository repository;@BeforeClass public static void beforeClass() { JPAHelper.entityManagerFactory("default");} @Before public void setup() { EntityManager manager = JPAHelper.currentEntityManager(); repository = new UserBusiness(manager);}
  43. 43. 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();}
  44. 44. Show me the code!
  45. 45. #greenbar
  46. 46. Referências DbUnit.org jIntegrity.comgithub.com/wbotelhos/jintegrity
  47. 47. Dúvidas?
  48. 48. Obrigado! (: jIntegrity WASHINGTON BOTELHO@wbotelhos | wbotelhos.com.br

×