test it! unit, mocking and in-container meet arquillian! ivan st. ivanov

Download Test it! Unit, mocking and in-container Meet Arquillian! Ivan St. Ivanov

Post on 19-Jan-2016

214 views

Category:

Documents

0 download

Embed Size (px)

TRANSCRIPT

Test it! Unit, mocking and in-container Meet Arquillian!

Test it! Unit, mocking and in-container Meet Arquillian!Ivan St. Ivanov

AgendaIntroduction to testingPure unit testing with JUnitStubs and mocks. Mockito libraryIn-container testing with Arquillian

CharacteristicsFastRun anywhereIDEBuild toolCI serverRepeatableLeverage known toolingLevelsUnitFunctionalIntegrationAcceptance

Unit testingSingle unit of codeIn isolationBenefits:Quick feedbackFacilitate changeDocument featuresLimitationsWont catch integration errorsToo much mocking

The purpose of automated testing is to enable change. Verifying correctness is just a nice side effect.

- Jeremy Norris

Test frameworks

Introduction to JUnitNo need to extend framework classesAnnotate test methods with @TestPreparation methods with @Before and @BeforeClassCleanup activities with @After and @AfterClassCheck with Assert methodsExtensible with test runnersExample JUnit test casepublic class FooBarTest {

private Foo foo;

@Before public void setup() { foo = new Foo(); foo.init(); }

@Test public void testBar() throws Exception { Assert.assertEquals("bar", foo.getBar()); }

@After public void tearDown() { foo.cleanup(); }}

Stubs and mocksUnits are not isolatedStubsTest doublesPredetermined behaviorMocksValidate behavior as wellUnit under test implies dependency injectionDependency injectabilitySample usecaseConference managerCacheWrong:Create Cache inside Conference managerLookup CacheCorrectConstructor or setter injectionMocking libraries

Greeting earthlings

Core principlesTests should be portable to any containerTests should be executable from both IDE and build toolThe platform should extend existing test frameworksStep 1 pick a containerContainer extensionsJBoss, Tomcat, Weld, Glassfish, Jetty, WebSphere, WebLogic

Step 2 connect the containerContainer typesEmbedded RemoteManaged

Step 3 package and deployShrinkWrap libraryDeploymentResolve from MavenCreate descriptors

Step 4 run the testTests runs in-containerCDI, EJB, JNDI availableNo need to mock most of the servicesPresent the result as a normal unit test

Step 5 undeploy the testUndeploy the test archiveDisconnect or stop the container

Thats not allPersistence extensionWarpDroneGrapheneAngularJS, Android, OSGi

ResourcesTestinghttp://en.wikipedia.org/wiki/Software_testingUnit testinghttp://en.wikipedia.org/wiki/Unit_testingMocks and stubshttp://martinfowler.com/articles/mocksArentStubs.html Arquillianhttp://aslakknutsen.github.io/presentations/https://rpestano.wordpress.com/2014/06/08/arquillian/https://rpestano.wordpress.com/2014/10/25/arquillian-and-mocks/ About this demoSlideshttp://bit.ly/bgjug-testing-slides Showcase initialhttp://bit.ly/bgjug-testing Showcase finalhttp://bit.ly/bgjug-testing-final