Interface AppFixture


  • public interface AppFixture

    Use the AppFixture to temporary change the active environment or global variables of an application in tests.

    Changes are rollbacked automatically to the previous value after the test.

    To use the AppFixture annotate your test class with either the IvyTest or IvyProcessTest annotation. Then add the AppFixture as parameter to any Test, BeforeAll, BeforeEach, AfterEach, AfterAll methods or the constructor of the test class.

    Changes made in BeforeAll and AfterAll methods are rollbacked after the execution of the test class. Changes made in BeforeEach, AfterEach and Test methods are rollbacked after the execution of each test.

    Example:

    
     @IvyTest
     class Test
     {
       @Test
       void test(AppFixture fixture)
       {
         assertThat(Ivy.var().get("limit")).isEqualTo("150");
         fixture.var("limit", "300");
         assertThat(Ivy.var().get("limit")).isEqualTo("300");
       }
     
    Since:
    9.1
    See Also:
    IvyTest, IvyProcessTest, Ivy
    API:
    This is a public API.
    • Method Detail

      • environment

        void environment​(String activeEnvironment)

        Changes the active environment for a test. The active environment will be automatically rollbacked to the previous environment when the test has been executed.

        Example:

        
           @Test
           void test(AppFixture fixture)
           {
             fixture.environment("Customer A");
             ...
           }
         
        Parameters:
        activeEnvironment -
        API:
        This public API is available in Java.
      • var

        void var​(String name,
                 String value)

        Changes the value of a global variable for a test. The value of the global variable will be automatically rollbacked to the previous value when the test has been executed.

        Example:

        
         @Test
         void test(AppFixture fixture)
         {
           assertThat(Ivy.var().get("limit")).isEqualTo("150");
           fixture.var("limit", "300");
           assertThat(Ivy.var().get("limit")).isEqualTo("300");
         }
         
        Parameters:
        name - the name of the global variable
        value - the new value of the global variable
        API:
        This public API is available in Java.
      • loginUser

        void loginUser​(IUser user)

        Login with an existing user. After the test the user is automatically logged out.

        Example:

        
           @Test
           void test(AppFixture fixture, @Named("James Bond") IUser user)
           {
             fixture.loginUser(user);
             ...
           }
         
        Parameters:
        user - the user to log in
        API:
        This public API is available in Java.
      • loginUser

        void loginUser​(String userName)

        Login with an existing user. After the test the user is automatically logged out.

        Example:

        
           @Test
           void test(AppFixture fixture)
           {
             fixture.loginUser("James Bond");
             ...
           }
         
        Parameters:
        userName - the name of the user
        API:
        This public API is available in Java.