Dron Bhattacharya
02/25/2023, 2:16 PMCLOVIS
02/25/2023, 3:26 PMkotlin.test
(recommended by JetBrains, JUnit-style) or #kotest (much, much more powerful and feature-complete). I recommend you start by learning these two.
In my opinion the best explanation of test doubles (mocks…) is this short article, as well as this longer explanation of the benefits of mocks. Note that not everyone agrees mocks are a good idea, but almost everyone agrees that "mocks used just because everyone else uses mocks" is actively harmful to your codebase.
The golden rules of testing are:
• a test failure should be as close to a bug report as you can get it to: reading the error message should tell you exactly what is broken and what needs to be fixed
• a test should fail for a specific reason (if a function can fail for 9 reasons, it should have 9 tests for failures + at least one test for the case where everything goes well)
• most tests should test very specific things, and a lot less tests should be used to test complete scenarios
• it is very important that if one thing changes with your software, a very few number of tests fail (those related to what you change). The more tests break when you change things that aren't related to them, the more tests will feel like a chore—on the opposite, if a single test fails per change, you're sure that your change doesn't impact anything else and is thus safe for deployingDron Bhattacharya
02/25/2023, 4:35 PMCLOVIS
02/25/2023, 4:37 PMDron Bhattacharya
02/25/2023, 4:37 PMCLOVIS
02/25/2023, 4:38 PMkotlin("jvm")
, kotlin("js")
, kotlin("multiplatform")
, etcDron Bhattacharya
02/25/2023, 4:45 PMkotlin("jvm")
and kotlin("multiplatform")
, I think...
I don't know detailed difference between the two.
But this is what I want to achieve in long term:
• At first I want to be capable of developing cli tools (like git, gradle, vim)
• Then I want to be capable of developing Desktop Utility apps like PowerToy.
• Also I want to do server side programming. (I have experience in Node.js and Express.js kind of frameworks, mainly JavaScript and python background). But I don't have any prior familiarity with tests
./*
* This file was generated by the Gradle 'init' task.
*
* This generated file contains a sample Kotlin application project to get you started.
* For more details take a look at the 'Building Java & JVM projects' chapter in the Gradle
* User Manual available at <https://docs.gradle.org/8.0/userguide/building_java_projects.html>
*/
plugins {
// Apply the org.jetbrains.kotlin.jvm Plugin to add support for Kotlin.
id("org.jetbrains.kotlin.jvm") version "1.8.10"
// Apply the application plugin to add support for building a CLI application in Java.
application
}
repositories {
// Use Maven Central for resolving dependencies.
mavenCentral()
}
dependencies {
// Use the Kotlin JUnit 5 integration.
testImplementation("org.jetbrains.kotlin:kotlin-test-junit5")
// Use the JUnit 5 integration.
testImplementation("org.junit.jupiter:junit-jupiter-engine:5.9.1")
// This dependency is used by the application.
implementation("com.google.guava:guava:31.1-jre")
implementation("com.github.ajalt.clikt:clikt:3.5.1")
testImplementation("org.junit.jupiter:junit-jupiter:5.8.1")
}
application {
// Define the main class for the application.
mainClass.set("taskmanner.AppKt")
}
tasks.named<Test>("test") {
// Use JUnit Platform for unit tests.
useJUnitPlatform()
}
this is generated by gradle init
.CLOVIS
02/25/2023, 4:59 PMkotlin()
plugins in a single Gradle project (build.gradle.kts
). You should choose one.
• JVM creates a Java library or application, meaning it will need the user to install Java to run. It's the easiest to get started because it's the oldest (so they had the time to fix most issues with it). For CLI tools, it's not great because the JVM is a bit slow to start (~0.3–0.5 seconds depending on your machine), but it's still by far the best way to make your first attempt
• JS is for websites or other JS scripts. You need a JavaScript executor to run it (a web browser or NodeJS). I guess you could create a NodeJS script like this, but I do not recommend it if you're not very familiar with NodeJS already. Plus, Node is slower than the JVM.
• Native is for native apps or libraries, that do not need anything else to run on your machine. It's the youngest platform by far, and the hardest to use. However, it's the best platform for CLI apps, so I recommend you make your first one or two on top of the JVM to understand how to do it, and then try using Native.
• Multiplatform is... all of them! It's the plugin to use when you want to create a single app that runs on multiple platforms. It's harder to configure so I don't recommend starting with it, but it's by far the most interesting in my opinionDron Bhattacharya
02/25/2023, 5:02 PMHumphrey
02/25/2023, 6:49 PMMarit van Dijk
02/27/2023, 5:52 AM