Skip to content

Provide an additional test toolkit library for spring framework.

License

Notifications You must be signed in to change notification settings

ahunigel/spring-test-toolkit

Repository files navigation

spring-test-toolkit

Provide an additional test toolkit library for spring framework.

Features

  • JUnit 4 @IfProfileValue profile source enhancement
    • @ProfileValueSourceConfiguration(EnvironmentProfileValueSource.class), use environment as profile value source
    • @ProfileValueSourceConfiguration(MergedSystemEnvAndPropertyProfileValueSource.class), use environment and system properties as profile value source
  • JUnit 4 @RunTestOnWindowsOnly annotation, restrict JUnit 4 tests running only on windows operation system
  • SpringParametersRunnerFactory
    • JUnit 4 @Parameterized support for SpringRunner, support run spring test with parameters
  • hamcrest additional matchers
    • JsonPathMatcher.jsonPath(jsonPathExpression, matcher)
    • JsonObjectMatcher.isJsonObject()
    • JsonArrayMatcher.isJsonArray()
  • JUnit additional Assertions
    • assertNotEmpty/assertBlank/assertNotBlank for Collection
    • assertNotEmpty for Map
    • assertNotEmpty/assertBlank/assertNotBlank for String
  • sprint-test enhanced request matchers
    • form()
    • matchAll(ResultMatcher... matchers)
    • allOf(ResultMatcher... matchers)
    • anyOf(ResultMatcher... matchers)
  • MockitoBaseTest

How to use

Step 1. Add the JitPack repository to your build file

allprojects {
    repositories {
        ...
        maven { url 'https://jitpack.io' }
    }
}

Step 2. Add the dependency

dependencies {
    implementation 'com.github.ahunigel:spring-test-toolkit:{version}'
}

Refer to https://jitpack.io/#ahunigel/spring-test-toolkit for details.

Step 3. Sample code

@ProfileValueSourceConfiguration(EnvironmentProfileValueSource.class)
public class FooTest {
}
@ProfileValueSourceConfiguration(MergedSystemEnvAndPropertyProfileValueSource.class)
public class FooTest {}
@RunTestOnWindowsOnly
public class FooTest {}
@RunWith(Parameterized.class)
@Parameterized.UseParametersRunnerFactory(SpringParametersRunnerFactory.class)
public class FooTest {}

References

See Also

TODOs

  • hamcrest collection matcher
    • hasItemsInOrder
  • JsonPath JsonProvider
    • NetMinidevJsonProvider