JAVA

  minte9
REMEMBERS




Last update:   14-03-2022

Junit

Create a test case for our demo.
T 
/**
 * Maven dependency test (junit)
 * 
 * mvn package
 * mvn test
 */

package com.minte9.junit;
import org.junit.Test;
import static org.junit.Assert.*;

public class DemoJunitTest {

    @Test public void testSum() {

        int a = 5;
        int b = 10;

        assertEquals(15, a+b);
    }
}

Pom

Add junit to pom.xml dependency.
 
<?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>

    <groupId>com.minte9</groupId>
    <artifactId>demoJunitTest</artifactId>
    <packaging>jar</packaging>
    <version>0.1.0</version>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <maven.compiler.source>11</maven.compiler.source>
        <maven.compiler.target>11</maven.compiler.target>
    </properties>

    <dependencies>
        <dependency>
            <groupId>joda-time</groupId>
            <artifactId>joda-time</artifactId>
            <version>2.9.2</version>
        </dependency>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.12</version>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-shade-plugin</artifactId>
                <version>3.2.4</version>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>shade</goal>
                        </goals>
                        <configuration>
                            <createDependencyReducedPom>false</createDependencyReducedPom>
                            <transformers>
                                <transformer implementation=
                        "org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                                    <mainClass>com.minte9.junit.DemoJunitTest</mainClass>
                                </transformer>
                            </transformers>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>

Build

Compile and run from terminal.
 
mvn package
mvn test

Questions     github Maven
Guava
        A B C D E F
🔔
1/1