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

The use of Error Handling in Swift 3:

5 tips to make your learning effective

How Can The Logistics Industry Accrue Benefits From Custom Mobile App Development?

what i have been waiting for has come !

Web Scalability for Startup Engineers — Book Review and Takeaways

What it’s like to do a coding bootcamp

Terminal vs. shell vs. CLI vs. Prompt

A Guide To Develop A Taxi Booking Mobile Application: Process, Features & Cost | Hyperlink…

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

Async Jersey + Kotlin Coroutines

Android Protobuf with kotlin and Wire

Why Android developer ❤ to use Kotlin as a main language besides Java?

Null Safety in Kotlin