1 Reply Latest reply on Aug 16, 2013 5:52 AM by smikloso

    Multiple deployments for Droidium

    smikloso

      Hello,

       

      We would like to be able to deploy more then one deployment into Android device. This is particulary useful when you have some application which depends on another one (or more then one) so in order to test instrumented application by Selendroid, you need to deploy all necessary APKs as well. Imagine some application which acts as a service (in Android terms) and is standalone. You have to deploy application you want to test _and_ that service apk which is used by instrumented one.

       

      Selendroid project is able to instrument only one application and you can not instrument more then one simultaneously since Selendroid server can be hooked only to 8080 port.

       

      The question how to recognize which @Deployment will be instrumented and which not raised, obviously. Imagine this scenario:

       

      @Deployment(name = "apk-under-test")
      public static Archive<?> getDeployment1() {
          // return application you want to test
         // this apk will be instrumented
      }
      
      @Deployment(name = "service-apk")
      public static Archive<?> getDeployment2() {
          // this apk will be just installed on Android
      }
      

       

      Right now, you can deploy just one apk which will be automatically instrumented by Selendroid. Every deployment is automatically instrumented but you do not need that in case described above. So naturally, you have to decide which @Deployment is going to be instrumented and which not. We figured it out like this:

       

       

      @Deployment(name = "apk-under-test")
      @Instrumentable
      public static Archive<?> getDeployment1() {
          // will be internally instrumented
      }
      
      @Deployment(name = "service-apk")
      public static Archive<?> getDeployment2() {
          // just install it
      }
      

       

      In code, it looks like this:

       

      https://gist.github.com/smiklosovic/c5c088075880d703db0b

       

      The logic is quite simple, you are listening to BeforeClass and filter @Deployment methods in order to get name of deployment archive which has @Deployment method annotated with @Instrumentable. So you get the name of deployment you are going to instrument. After  that, you are listening to AfterDeploy where you iterate over deployments and check it the name of it equals to filtered previously and if yes, you fire event with the archive and Selendroid server will be instrumented subsequently.

       

      Time for some questions We do not know if this is good solution because:

       

      I am implementing something "ugly" and it looks like a hack. It can work but and we are bringing new problems like

      a) We are validating deployments in BeforeClass method but deployments do not need to be present at all in the test class which implies that after putting this on classpath it is broken by default when no @Deployments are present

      b) We are repeating what is already done in AnnotationDeploymentScenarioGenerator

      c) We do not stick to Arquillian way of doing things like implement what is necessary throught spi and place it on classpath

       

      So the best solution seems to be to implement own DeploymentScenarioGenerator but it means that we need to reimplement nearly the whole AnnotationDeploymentScenarioGenerator and add there that @Instrumentable stuff and I am not sure if we just do not repeat ourselves too much here.

       

      Tips & hints?