This library helps to handle custom validations tests in Java.
- Java 1.8+
To start, add that Maven dependency:
<dependency>
<groupId>br.com.leverinfo</groupId>
<artifactId>test</artifactId>
<version>0.2.0</version>
</dependency>
or Gradle:
implementation 'br.com.leverinfo:test:0.2.0'
This must be use together with br.com.leverinfo:validation
, so you need to import it as well:
Maven:
<dependency>
<groupId>br.com.leverinfo</groupId>
<artifactId>validation</artifactId>
<version>0.4.0</version>
</dependency>
Gradle:
implementation 'br.com.leverinfo:validation:0.4.0'
Assuming that we have an example like the one described here...
...then, you can use it like this:
...
import br.com.leverinfo.test.ValidationAssertions;
...
public class FooTest {
...
public void testPrintName {
ValidationAssertions.assertThatRequiredArgumentException()
.isThrowingBy(() -> foo.printName(null))
.withValidationMessage(MyMessages.NAME_REQUIRED);
}
}
Below are the available assertions:
assertThatRequiredArgumentException
- Asserts that aRequiredArgumentException
was thrownassertThatInvalidArgumentException
- Asserts that aInvalidArgumentException
was thrownassertThatNotAllowedException
- Asserts that aNotAllowedException
was thrownassertThatNotFoundException
- Asserts that aNotFoundException
was thrownassertThatDependencyNotFoundException
- Asserts that aDependencyNotFoundException
was thrownassertThatDuplicatedException
- Asserts that aDuplicatedException
was thrown
withValidationMessage
- Validate if the thrown exception has expectedValidationMessage
withParams
- Validate if the thrown exception has correct params
- Create unit tests
- Configure CI/CD pipeline
Your contribution is appreciated.