needle
play

NEEDLE for Java EE - PowerPoint PPT Presentation

NEEDLE for Java EE Need(le)(for(Speed((Effec<ve(Unit(Tes<ng(for(Java(EE( ( Heinz(Wilming,(akquinet(AG( Version(2.0( h-p://needle.spree.de/( Mo<va<on( Why$do$we$Test?$ ! Confidence ! Cost(Reduc<on( ! Be-er(Design( !


  1. NEEDLE for Java EE Need(le)(for(Speed(–(Effec<ve(Unit(Tes<ng(for(Java(EE( ( Heinz(Wilming,(akquinet(AG( Version(2.0( h-p://needle.spree.de/( •

  2. Mo<va<on( Why$do$we$Test?$ ! Confidence ! Cost(Reduc<on( ! Be-er(Design( ! Documenta<on( ! Less(Debug(Time( Version(2.0( h-p://needle.spree.de/( •

  3. Unit(tes<ng( The$levels$of$tes0ng$ ! Unit( NEEDLE ! Integra<on( for Java EE ! Acceptance( ( Version(2.0( h-p://needle.spree.de/( •

  4. Unit(tes<ng( Run0me$environment$ Version(2.0( h-p://needle.spree.de/( •

  5. Unit(tes<ng( Unit9Test$environment$ Version(2.0( h-p://needle.spree.de/( •

  6. Unit(tes<ng( Unit9Test$environment$ OrderDao mock = mock (OrderDao. class ); new ShoppingCart(); Version(2.0( h-p://needle.spree.de/( •

  7. Unit(tes<ng( Breaking$the$encapsula0on$ public class ShoppingCart { @Inject protected OrderDao orderDao ; ... } Version(2.0( h-p://needle.spree.de/( •

  8. Unit(tes<ng( Breaking$the$encapsula0on$ public class ShoppingCart { @Inject private OrderDao orderDao ; ... (((((((/*( (((*(for(unit(test(only( (((*/ protected void setOrderDao(OrderDao dao){ orderDao = dao; } } Version(2.0( h-p://needle.spree.de/( •

  9. Unit(tes<ng( Using$reflec0on$ public class ShoppingCartTest { private ShoppingCart shoppingCart; private OrderDao mock; @Before public void setup() throws Exception { shoppingCart = new ShoppingCartService(); mock = mock (OrderDao. class ); Field field = ShoppingCart. class. getDeclaredField("orderDao"); field.setAccessible( true ); field.set(shoppingCart, mock); } @Test public void testCheckout() { ... } } Version(2.0( h-p://needle.spree.de/( •

  10. Need(le)(for(Speed( Effec0ve$Unit$Tes0ng$for$Java$EE$ ! out(of(container(tes<ng( ! test(components(in(isola<on( ! reduce(test(setup(code( ! analyze(dependencies(( and(provide(mocks( ! Fast(in(development( and(execu<on( Version(2.0( h-p://needle.spree.de/( •

  11. Need(le)(for(Speed( public class ShoppingCartTest { @Rule public NeedleRule needleRule = new NeedleRule(); @ObjectUnderTest private ShoppingCart shoppingCart; @Test public void testCheckout() { boolean checkout = shoppingCart.checkout(); assertTrue (checkout); } } Version(2.0( h-p://needle.spree.de/( •

  12. Need(le)(for(Speed( Instan<a<on(of( @ObjectUnderTest ( Components( ( Dependency(Injec<on( ! Field( ! Method( ! Constuctor( Default(are(Mock(Objects( Version(2.0( h-p://needle.spree.de/( •

  13. Need(le)(for(Speed( Injec0on$Provider$ Out]of]the]box( @Inject, @EJB, @Resource, @PersistenceContext, @PersistenceUnit Configura<on(of(addi<onal(Annota<ons( ! e.g.(Seam(2(]( @In,@Logger ( ( Configura<on(of(addi<onal(injec<on(provider( ! e.g. javax.inject.Qualifier Version(2.0( h-p://needle.spree.de/( •

  14. Need(le)(for(Speed( Mock$injec0on$ public class ShoppingCartTest { @Rule public NeedleRule needleRule = new NeedleRule(); @ObjectUnderTest private ShoppingCart shoppingCart; @Inject private OrderDao orderDaoMock ; @Test public void testCheckout() { when (orderDaoMock.find( anyLong ())).thenReturn( new Order()); boolean checkout = shoppingCart.checkout(); assertTrue (checkout); } } Version(2.0( h-p://needle.spree.de/( •

  15. Need(le)(for(Speed( Tes0ng$object$graphs$ Provide(own(objects( ( Mul<ple(( @ObjectUnderTest ( Components( Wiring(complex(object(graph( ! @InjectInto ! @InjectIntoMany ( Version(2.0( h-p://needle.spree.de/( •

  16. Need(le)(for(Speed( Database$tes0ng$ via(JPA(Provider,(e.g.(EclipseLink(or(Hibernate( ( ( En<tyManager(crea<on(and(injec<on( ( ( Op<onal:(Execute(Database(opera<on(on(test(setup( and(teardown(( ! Import(SQL(Scripts( ! Dele<ng(test(data(aaer(the(test(execu<on( Version(2.0( h-p://needle.spree.de/( •

  17. Need(le)(for(Speed( public class OrderDaoTest { @Rule public DatabaseRule dbRule = new DatabaseRule(); @Rule public NeedleRule needleRule = new NeedleRule(dbRule); @ObjectUnderTest private OrderDao orderDao; @Test public void testFind() { Order order = new OrderTestdataBuilder().buildAndSave(); Order orderFromDb = orderDao.find(order.getId()); assertEquals (checkout); } } Version(2.0( h-p://needle.spree.de/( •

  18. Live(Demo( DEMO$ h-p://seam]archetype.sourceforge.net/jbosscc]seam]archetype/1.4/javaee.html( ( Version(2.0( h-p://needle.spree.de/( •

  19. Summary( Summary$ Fast( Less(Glue(Code( Keep(Dependencies(Private( Flexible(&(Extensible(( Developer(Happiness(;])( Version(2.0( h-p://needle.spree.de/( •

  20. Summary( Get$Started$Today!$ <dependency> <groupId> de.akquinet.jbosscc </groupId> <artifactId> jbosscc-needle </artifactId> <version> 2.1 </version> <scope> test </scope> </dependency> Version(2.0( h-p://needle.spree.de/( •

  21. Links( http://needle.spree.de http://sourceforge.net/projects/jbosscc-needle/ heinz.wilming@akquinet.de http://blog.akquinet.de/ Version(2.0( h-p://needle.spree.de/( •

  22. NEEDLE for Java EE Version(2.0( h-p://needle.spree.de/( •

Recommend


More recommend