JUnit 4 Einzeltest
Ein einzelner @Test deckt genau einen Beispieldatensatz ab.
Vollständiger Legacy-Modern-Vergleich aller Java-Klassen, Tests, Maven-POMs und relevanten Ressourcen dieses Moduls. Jede Datei ist genau einmal einer fachlich passenden Vergleichsgruppe zugeordnet.
Ein einzelner @Test deckt genau einen Beispieldatensatz ab.
Ein @ParameterizedTest führt dieselbe Aussage mit mehreren repräsentativen Datensätzen aus.
Die Ähnlichkeit ist eine technische Orientierung auf normalisiertem Quelltext. Sie ersetzt keine fachliche Bewertung.
| Vergleichsgruppe | Legacy-Dateien | Modern-Dateien | Legacy-Zeilen | Modern-Zeilen | Ähnlichkeit |
|---|---|---|---|---|---|
| Build-Konfiguration | 1 | 1 | 30 | 34 | 56% |
| Produktionscode | 1 | 1 | 9 | 9 | 100% |
| Testcode | 1 | 1 | 11 | 16 | 39% |
Das Pair-POM bindet die Legacy- und Modern-Submodule zusammen und gehört deshalb ebenfalls zur vollständigen Codeabdeckung.
JUnit-4- und JUnit-5-Konfiguration wird verglichen.
| Legacy-Dateien | Modern-Dateien | Einordnung |
|---|---|---|
| pom.xml | pom.xml | Direktvergleich Semantische Ähnlichkeit: 56% |
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>at.aydin.academy</groupId>
<artifactId>19junittesting-pair</artifactId>
<version>1.0.0</version>
<relativePath>../pom.xml</relativePath>
</parent>
<artifactId>junit4-legacy</artifactId>
<packaging>jar</packaging>
<name>JUnit 4 Legacy</name>
<dependencies>
<dependency><groupId>junit</groupId><artifactId>junit</artifactId><version>4.13.2</version><scope>test</scope></dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
</plugin>
</plugins>
</build>
</project><?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>at.aydin.academy</groupId>
<artifactId>19junittesting-pair</artifactId>
<version>1.0.0</version>
<relativePath>../pom.xml</relativePath>
</parent>
<artifactId>junit5-modern</artifactId>
<packaging>jar</packaging>
<name>JUnit 5 Modern</name>
<dependencies>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<scope>test</scope>
</dependency>
<dependency><groupId>org.junit.jupiter</groupId><artifactId>junit-jupiter-params</artifactId><scope>test</scope></dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>Der Fachcode bleibt bewusst gleich, um Testdesign isoliert zu vergleichen.
| Legacy-Dateien | Modern-Dateien | Einordnung |
|---|---|---|
| VatCalculator.java | VatCalculator.java | Direktvergleich Semantische Ähnlichkeit: 100% |
package at.aydin.lab.testing.legacy;
// Design Pattern: Stateless Service – hält die Berechnung zustandsfrei und isoliert testbar.
public final class VatCalculator {
public double gross(double net, double rate) {
if (net < 0 || rate < 0) throw new IllegalArgumentException();
return Math.round(net * (1 + rate) * 100.0) / 100.0;
}
}package at.aydin.lab.testing.modern;
// Design Pattern: Stateless Service – hält die Berechnung zustandsfrei und isoliert testbar.
public final class VatCalculator {
public double gross(double net, double rate) {
if (net < 0 || rate < 0) throw new IllegalArgumentException();
return Math.round(net * (1 + rate) * 100.0) / 100.0;
}
}Assertions, Lifecycle und Parametrisierung werden direkt gegenübergestellt.
| Legacy-Dateien | Modern-Dateien | Einordnung |
|---|---|---|
| VatCalculatorTest.java | VatCalculatorTest.java | Direktvergleich Semantische Ähnlichkeit: 39% |
package at.aydin.lab.testing.legacy;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
public class VatCalculatorTest {
@Test
public void calculatesTwentyPercent() {
assertEquals(120.0, new VatCalculator().gross(100, 0.2), 0.001);
}
}package at.aydin.lab.testing.modern;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.CsvSource;
import static org.junit.jupiter.api.Assertions.assertEquals;
// Design Pattern: Parameterized Test
// Zweck: Ein fachliches Verhalten wird mit mehreren repräsentativen Datenkombinationen geprüft.
class VatCalculatorTest {
@ParameterizedTest
@CsvSource({
"100,0.2,120", "50,0.1,55", "0,0.2,0"
}) void calculates(double net, double rate, double expected) {
assertEquals(expected, new VatCalculator().gross(net, rate));
}
}