0 Replies Latest reply on Aug 31, 2010 11:37 AM by Aslak Knutsen

    Spock Arquillian Extension

    Aslak Knutsen Master

      I got inspired last night be TourqeBox using Arquillian to test Ruby apps. So as a step in making a RSpec Arquillian integration, I started on the next best thing from the Java Spec world, Spock.

       

      Spock is a testing and specification framework for Java and Groovy applications. What makes it stand out from the crowd is its beautiful and highly expressive specification language. Thanks to its JUnit runner, Spock is compatible with most IDEs, build tools, and continuous integration servers. Spock is inspired from JUnit, jMock, RSpec, Groovy, Scala, Vulcans, and other fascinating life forms.

       

      class AccountServiceSpecification extends Specification {
      
          @Deployment
          def static JavaArchive "create deployment"() {
              return ShrinkWrap.create(JavaArchive.class)
                      .addClasses(AccountService.class, Account.class, SecureAccountService.class)
                      .addManifestResource(EmptyAsset.INSTANCE, "beans.xml");
          }
      
          @Inject 
          AccountService service
              
          def "transferring between accounts should result in account withdrawl and diposit"() {
              when:
              service.transfer(from, to, amount)
              
              then:
              from.balance == fromBalance
              to.balance == toBalance
              
              where:
              from <<         [new Account(100),  new Account(10)]
              to <<           [new Account(50),   new Account(90)]
              amount <<       [50,                10]
              fromBalance <<  [50,                0]
              toBalance <<    [100,               100]
          }
      }
      

       

      Here you have a Spock Groovy test case running in Weld-SE using Arquillian in the background. Pretty neat..

       

      The Spock Extension can be found in the arquillian-extensions git repo:

      http://github.com/arquillian/arquillian-extensions/blob/spock/spock-arquillian-extension/

       

      -aslak-

       

      ps:

      It's missing a TestRunner implementation, so no Remote test execution available yet. But Embedded Standalone contianers should work, Weld, OpenEJB, IronJacamar, OpenWebBeans etc..