Skip to content

Instantly share code, notes, and snippets.

@creedasaurus
Created August 23, 2018 00:13
Show Gist options
  • Save creedasaurus/a116f3d9014e62837646e6c843dc9732 to your computer and use it in GitHub Desktop.
Save creedasaurus/a116f3d9014e62837646e6c843dc9732 to your computer and use it in GitHub Desktop.
JUnit 5 Gradle setup
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertNotNull;
public class AppTest {
@Test public void testAppHasAGreeting() {
App classUnderTest = new App();
assertNotNull("app should have a greeting", classUnderTest.getGreeting());
}
}
plugins {
id 'java'
id 'application'
}
version = '1.0'
mainClassName = 'App'
dependencies {
testCompile('org.junit.jupiter:junit-jupiter-api:5.2.0')
testCompile('org.junit.jupiter:junit-jupiter-params:5.2.0')
testRuntime('org.junit.jupiter:junit-jupiter-engine:5.2.0')
}
jar {
manifest {
attributes 'Implementation-Title': 'App',
'Implementation-Version': version,
'Main-Class': mainClassName
}
}
test {
useJUnitPlatform()
testLogging {
events "passed", "skipped", "failed"
}
}
repositories {
mavenCentral()
}
gradle run # run project
gradle test # run tests
gradle clean # clean out build artifacts
gradle build jar # build the jar file
java -jar ./build/libs/App-1.0.jar # run jar file using java
gradle clean build jar # stringing gradle commands together
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment