Interface AppFixture
Use the AppFixture to temporary change the active environment or 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:
- API:
- This is a public API.
-
Method Summary
Modifier and TypeMethodDescriptionvoid
Changes the value of a configuration of the current application for a test.void
Changes the value of a configuration of the current application for a test.void
Login with an existing user.void
Login with an existing user.void
Changes the value of a variable for a test.
-
Method Details
-
var
Changes the value of a variable for a test. The value of the 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 variablevalue
- the new value of the variable- API:
- This public API is available in Java.
-
config
Changes the value of a configuration of the current application for a test. The value of the configuration will be automatically rollbacked to the previous value when the test has been executed.
Example:
@Test void test(AppFixture fixture) { assertThat(Ivy.rest().client("jsonPlaceholder").getUri().toString()).isEqualTo("https://jsonplaceholder.typicode.com/"); fixture.config("RestClients.jsonPlaceholder.Url", "${ivy.app.baseurl}/api/testMock"); assertThat(Ivy.rest().client("jsonPlaceholder").getUri().toString()).isEqualTo("http://localhost:8080/test/api/testMock"); }
- Parameters:
key
- the key of the configurationvalue
- the new value of the configuration- Since:
- 9.4
- API:
- This public API is available in Java.
-
config
Changes the value of a configuration of the current application for a test. The value of the configuration will be automatically rollbacked to the previous value when the test has been executed.
Example:
@Test void test(AppFixture fixture) { fixture.config("RestClients.ChatGPT.Features", List.of(ch.ivyteam.ivy.rest.client.security.CsrfHeaderFeature.class.getName())); }
- Parameters:
key
- the key of the configurationvalue
- the new value of the configuration- Since:
- 10.0.8
- API:
- This public API is available in Java.
-
loginUser
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
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.
-