Kotlin/Gradle/JUnit starter project

1. Create a project

  1. Download and install IntelliJ Community, free for Java/Kotlin projects. Alternatively, you can use IntelliJ Ultimate EAP (no subscription required).
  2. Go to “File” ⇀ “New project”.
  3. Activate “Create Git repository”.
  4. Pick “Kotlin” as language.
  5. Pick “Gradle” as the build system.
  6. Pick “Kotlin” as Gradle DSL. Since we’re using Kotlin, it makes sense that the Gradle DSL is Kotlin.
  7. Fill in the remaining details, and press “Create”.

2. Setup Git

To ensure you don’t lose your work and can always go back in time, ensure you set up Git — even if only locally.

  1. Start a new git repository (git init) if you haven’t picked “Create Git repository” before.
  2. Create a .gitignore file with the following content, and commit all the changes:
/.gradle
/.idea
/build

3. Update Gradle/Kotlin

The IDE doesn’t use the latest versions of Gradle and Kotlin, so we need to do it manually.

  1. Check the latest version of Gradle (e.g. 7.4.2) and update the file gradle/wrapper/gradle-wrapper.properties accordingly.
  2. Check the latest version of Kotlin (e.g. 1.6.21) and update the file build.gradle.kts accordingly.
plugins {
kotlin("jvm") version "1.6.21". // or 1.+ for always latest
}

4. Set up JUnit

  1. At build.gradle.kts’s dependencies, set up JUnit 5:
dependencies {
testImplementation("org.junit.jupiter:junit-jupiter-api:5.+")
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:5.+")
}
tasks.withType<Test> {
useJUnitPlatform()
}

2. Create a dummy test (src/test/kotlin/DummyTest.kt) and run it just to prove that the JUnit setup is good:

class TestAmazonCart {
@Test
fun `everything is fine`() {
assertTrue(true)
}
}

You can also run the tests with ./gradlew test

--

--

--

I write about Lean, TDD, CI/CD, trunk-based dev., user-centric dev, DDD, coding good practices, testing

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

FIND POTENTIAL LEADS WITH LINKEDIN SEARCH IN 6 EASY STEPS

Genesis of M6’s Datalake

Tutorial: Using the MTurk API with the AWS SDK for C# with .NET

Setup FortiGate on AWS and Force All EC2'sTraffic Through It

picoCTF: Nice netcat…

BlackJack in Python

Cyber Research #28

How To Make Search Fields Dynamic in the Django REST Framework

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Luís Soares

Luís Soares

I write about Lean, TDD, CI/CD, trunk-based dev., user-centric dev, DDD, coding good practices, testing

More from Medium

Testing tools for Kotlin. Quick recap in 2022.

How to Avoid Model Changes Nightmare in Java or Kotlin

Async Jersey + Kotlin Coroutines

Kotlin Flows Unit Tests

A screen shot of a popup window that helps you generate a test class