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