JUnit 4 & 5 Test mit Maven
This commit is contained in:
parent
3e5ed9396c
commit
93b4abc1b3
|
@ -1,2 +1,3 @@
|
||||||
Java 2.iml
|
Java 2.iml
|
||||||
|
java2.iml
|
||||||
target
|
target
|
34
pom.xml
34
pom.xml
|
@ -10,35 +10,32 @@
|
||||||
<artifactId>java2</artifactId>
|
<artifactId>java2</artifactId>
|
||||||
<version>1.0-SNAPSHOT</version>
|
<version>1.0-SNAPSHOT</version>
|
||||||
|
|
||||||
|
<properties>
|
||||||
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
|
</properties>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
<plugins>
|
<plugins>
|
||||||
<plugin>
|
<plugin>
|
||||||
<artifactId>maven-compiler-plugin</artifactId>
|
<artifactId>maven-compiler-plugin</artifactId>
|
||||||
|
<version>3.7.0</version>
|
||||||
<configuration>
|
<configuration>
|
||||||
<source>1.8</source>
|
<source>1.8</source>
|
||||||
<target>1.8</target>
|
<target>1.8</target>
|
||||||
</configuration>
|
</configuration>
|
||||||
</plugin>
|
</plugin>
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
|
||||||
<artifactId>maven-surefire-plugin</artifactId>
|
<artifactId>maven-surefire-plugin</artifactId>
|
||||||
<version>2.19.1</version>
|
<version>2.19.1</version>
|
||||||
|
<configuration>
|
||||||
|
<test>de.joethei.hs.java2.tests.*</test>
|
||||||
|
</configuration>
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.junit.platform</groupId>
|
<groupId>org.junit.platform</groupId>
|
||||||
<artifactId>junit-platform-surefire-provider</artifactId>
|
<artifactId>junit-platform-surefire-provider</artifactId>
|
||||||
<version>1.0.1</version>
|
<version>1.0.1</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
|
||||||
<groupId>org.junit.vintage</groupId>
|
|
||||||
<artifactId>junit-vintage-engine</artifactId>
|
|
||||||
<version>4.12.1</version>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.junit.jupiter</groupId>
|
|
||||||
<artifactId>junit-jupiter-engine</artifactId>
|
|
||||||
<version>5.0.1</version>
|
|
||||||
</dependency>
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
</plugin>
|
</plugin>
|
||||||
</plugins>
|
</plugins>
|
||||||
|
@ -48,7 +45,7 @@
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.junit.jupiter</groupId>
|
<groupId>org.junit.jupiter</groupId>
|
||||||
<artifactId>junit-jupiter-api</artifactId>
|
<artifactId>junit-jupiter-api</artifactId>
|
||||||
<version>5.0.1</version>
|
<version>5.1.0</version>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
|
@ -57,7 +54,18 @@
|
||||||
<version>4.12</version>
|
<version>4.12</version>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.junit.jupiter</groupId>
|
||||||
|
<artifactId>junit-jupiter-engine</artifactId>
|
||||||
|
<version>5.1.0</version>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.junit.vintage</groupId>
|
||||||
|
<artifactId>junit-vintage-engine</artifactId>
|
||||||
|
<version>4.12.1</version>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
|
|
||||||
</project>
|
</project>
|
|
@ -1,6 +1,7 @@
|
||||||
package de.joethei.hs.java2.tests;
|
package de.joethei.hs.java2.tests;
|
||||||
|
|
||||||
import de.joethei.hs.java2.praktikum1.GrosseZahl;
|
import de.joethei.hs.java2.praktikum1.GrosseZahl;
|
||||||
|
import org.junit.jupiter.api.DisplayName;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.*;
|
import static org.junit.jupiter.api.Assertions.*;
|
||||||
|
@ -8,17 +9,16 @@ import static org.junit.jupiter.api.Assertions.*;
|
||||||
class GrosseZahlTest {
|
class GrosseZahlTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@DisplayName("Konstruktoren")
|
||||||
void constructors() {
|
void constructors() {
|
||||||
/*
|
|
||||||
Executable exec = () -> new GrosseZahl("Hallo Welt");
|
|
||||||
assertThrows(NumberFormatException.class, exec);
|
|
||||||
*/
|
|
||||||
assertEquals(new GrosseZahl("1456"), new GrosseZahl(1456));
|
assertEquals(new GrosseZahl("1456"), new GrosseZahl(1456));
|
||||||
assertNotEquals(new GrosseZahl("1234"), new GrosseZahl(1233));
|
assertNotEquals(new GrosseZahl("1234"), new GrosseZahl(1233));
|
||||||
assertNotEquals(new GrosseZahl(14), 14);
|
assertNotEquals(new GrosseZahl(14), 14);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@DisplayName("Addition")
|
||||||
void add() {
|
void add() {
|
||||||
assertEquals(new GrosseZahl(42), new GrosseZahl("40").add(new GrosseZahl(2)));
|
assertEquals(new GrosseZahl(42), new GrosseZahl("40").add(new GrosseZahl(2)));
|
||||||
assertEquals(new GrosseZahl("42"), new GrosseZahl(40).add(new GrosseZahl(2)));
|
assertEquals(new GrosseZahl("42"), new GrosseZahl(40).add(new GrosseZahl(2)));
|
||||||
|
@ -31,15 +31,16 @@ class GrosseZahlTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@DisplayName("Substraktion")
|
||||||
void sub() {
|
void sub() {
|
||||||
assertEquals(new GrosseZahl(42), new GrosseZahl(100).sub(new GrosseZahl(58)));
|
assertEquals(new GrosseZahl(42), new GrosseZahl(100).sub(new GrosseZahl(58)));
|
||||||
assertNotEquals(new GrosseZahl(43), new GrosseZahl(100).sub(new GrosseZahl(58)));
|
assertNotEquals(new GrosseZahl(43), new GrosseZahl(100).sub(new GrosseZahl(58)));
|
||||||
assertEquals(new GrosseZahl(100), new GrosseZahl(150).sub(new GrosseZahl(50)));
|
assertEquals(new GrosseZahl(100), new GrosseZahl(150).sub(new GrosseZahl(50)));
|
||||||
assertEquals(new GrosseZahl(0), new GrosseZahl(10).sub(new GrosseZahl("10")));
|
assertEquals(new GrosseZahl(0), new GrosseZahl(10).sub(new GrosseZahl("10")));
|
||||||
assertEquals(new GrosseZahl(0), new GrosseZahl(10).sub(new GrosseZahl(50)));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@DisplayName("Multiplikation")
|
||||||
void mult() {
|
void mult() {
|
||||||
assertEquals(new GrosseZahl(15), new GrosseZahl("5").mult(new GrosseZahl(3)));
|
assertEquals(new GrosseZahl(15), new GrosseZahl("5").mult(new GrosseZahl(3)));
|
||||||
assertNotEquals(new GrosseZahl("15"), new GrosseZahl("4").mult(new GrosseZahl(3)));
|
assertNotEquals(new GrosseZahl("15"), new GrosseZahl("4").mult(new GrosseZahl(3)));
|
||||||
|
@ -47,6 +48,7 @@ class GrosseZahlTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@DisplayName("less")
|
||||||
void less() {
|
void less() {
|
||||||
assertTrue(new GrosseZahl("1234").less(new GrosseZahl("12345")));
|
assertTrue(new GrosseZahl("1234").less(new GrosseZahl("12345")));
|
||||||
assertFalse(new GrosseZahl("12345").less(new GrosseZahl("1234")));
|
assertFalse(new GrosseZahl("12345").less(new GrosseZahl("1234")));
|
||||||
|
@ -56,12 +58,14 @@ class GrosseZahlTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@DisplayName("toString()")
|
||||||
void toStringTest() {
|
void toStringTest() {
|
||||||
assertEquals("45", new GrosseZahl(45).toString());
|
assertEquals("45", new GrosseZahl(45).toString());
|
||||||
assertEquals("45", new GrosseZahl("45").toString());
|
assertEquals("45", new GrosseZahl("45").toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@DisplayName("größter gemeinsamer Teiler")
|
||||||
void ggT() {
|
void ggT() {
|
||||||
assertEquals(new GrosseZahl(3), new GrosseZahl(45).ggT(new GrosseZahl(21)));
|
assertEquals(new GrosseZahl(3), new GrosseZahl(45).ggT(new GrosseZahl(21)));
|
||||||
assertEquals(new GrosseZahl(70), new GrosseZahl(1400).ggT(new GrosseZahl(210)));
|
assertEquals(new GrosseZahl(70), new GrosseZahl(1400).ggT(new GrosseZahl(210)));
|
||||||
|
|
Loading…
Reference in New Issue