Commit 9dc7dd22 authored by Hallvard Trætteberg's avatar Hallvard Trætteberg
Browse files

parameterisert test

parent 3665d552
Pipeline #90514 passed with stage
in 1 minute and 24 seconds
...@@ -10,13 +10,19 @@ ...@@ -10,13 +10,19 @@
<dependency> <dependency>
<groupId>org.junit.jupiter</groupId> <groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId> <artifactId>junit-jupiter-api</artifactId>
<version>5.4.2</version> <version>5.7.0</version>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.junit.jupiter</groupId> <groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId> <artifactId>junit-jupiter-engine</artifactId>
<version>5.4.2</version> <version>5.7.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-params</artifactId>
<version>5.7.0</version>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
</dependencies> </dependencies>
......
package antipatterns; package antipatterns;
import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;
public class DataClassWithValidationTest { public class DataClassWithValidationTest {
private DataClassWithValidation instance1;
@BeforeEach
public void setup() {
instance1 = new DataClassWithValidation();
}
@Test @Test
public void testConstructor() { public void testConstructor() {
try { try {
...@@ -32,4 +42,11 @@ public class DataClassWithValidationTest { ...@@ -32,4 +42,11 @@ public class DataClassWithValidationTest {
public void testBetterConstructor_validName() { public void testBetterConstructor_validName() {
new DataClassWithValidation("ok name"); new DataClassWithValidation("ok name");
} }
@ParameterizedTest
@ValueSource(strings = {" starts with blank"})
public void testBetterSetName_invalidName(String name) {
Assertions.assertThrows(IllegalArgumentException.class, () -> instance1.setName(name));
}
} }
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment