Uploaded image for project: 'Arquillian'
  1. Arquillian
  2. ARQ-2189

Injection into JUnit rule does not work properly

    XMLWordPrintable

Details

    • Bug
    • Resolution: Unresolved
    • Major
    • None
    • 1.4.0.Final
    • None
    • None

    Description

      We just upgraded our Arquillian version to 1.4.0.Final and now the JUnit rules do not work properly.

      We have a LoginRule like

      public class LoginRule implements TestRule
      {
         @EJB
         private SecurityManagement securityManagement;
      
         private String username;
         private String password;
      
         public LoginRule(String username, String password)
         {
            this.username = username;
            this.password = password;
         }
      
         @Override
         public Statement apply(Statement base, Description description)
         {
            return new Statement()
            {
               public void evaluate() throws Throwable
               {
                  login();
                  base.evaluate();
               }
            };
         }
      
         ...
      }
      

      If we use it in a test like

         @Rule
         public LoginRule login = new LoginRule("user", "pass");
      
         @Test
         public void test()
         {
            // do something with login
         }
      

      Unfortunately this does not work anymore, as securityManagement was not injected and so the login method in the rule fails which would have used it.

      With a subclass with default constructor like

      public class CertainLoginRule extends LoginRule
      {
         public CertainLoginRule()
         {
            super("user", "pass");
         }
      }
      

      and the usage

         @Rule
         public CertainLoginRule login = new CertainLoginRule();
      
         @Test
         public void test()
         {
            // do something with login
         }
      

      it works properly.

      We tested different variations with subclass, without, constructors with parameters, without and so on.

      The significant part seems to be the parameters to the constructor. If there are none injection works as expected, if there are some, injection is not done.

      Attachments

        Activity

          People

            Unassigned Unassigned
            Vampire0 Björn Kautler (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated: