https://kotlinlang.org logo
Channels
100daysofcode
100daysofkotlin
100daysofkotlin-2021
advent-of-code
aem
ai
alexa
algeria
algolialibraries
amsterdam
android
android-architecture
android-databinding
android-studio
androidgithubprojects
androidthings
androidx
androidx-xprocessing
anime
anko
announcements
apollo-kotlin
appintro
arabic
argentina
arkenv
arksemdevteam
armenia
arrow
arrow-contributors
arrow-meta
ass
atlanta
atm17
atrium
austin
australia
austria
awesome-kotlin
ballast
bangladesh
barcelona
bayarea
bazel
beepiz-libraries
belgium
benchmarks
berlin
big-data
books
boston
brazil
brikk
budapest
build
build-tools
bulgaria
bydgoszcz
cambodia
canada
carrat
carrat-dev
carrat-feed
chicago
chile
china
chucker
cincinnati-user-group
cli
clikt
cloudfoundry
cn
cobalt
code-coverage
codeforces
codemash-precompiler
codereview
codingame
codingconventions
coimbatore
collaborations
colombia
colorado
communities
competitive-programming
competitivecoding
compiler
compose
compose-android
compose-desktop
compose-hiring
compose-ios
compose-mp
compose-ui-showcase
compose-wear
compose-web
confetti
connect-audit-events
corda
cork
coroutines
couchbase
coursera
croatia
cryptography
cscenter-course-2016
cucumber-bdd
cyprus
czech
dagger
data2viz
databinding
datascience
dckotlin
debugging
decompose
decouple
denmark
deprecated
detekt
detekt-hint
dev-core
dfw
docs-revamped
dokka
domain-driven-design
doodle
dsl
dublin
dutch
eap
eclipse
ecuador
edinburgh
education
effective-kotlin
effectivekotlin
emacs
embedded-kotlin
estatik
event21-community-content
events
exposed
failgood
fb-internal-demo
feed
firebase
flow
fluid-libraries
forkhandles
forum
fosdem
fp-in-kotlin
framework-elide
freenode
french
fritz2
fuchsia
functional
funktionale
gamedev
ge-kotlin
general-advice
georgia
geospatial
german-lang
getting-started
github-workflows-kt
glance
godot-kotlin
google-io
gradle
graphic
graphkool
graphql
graphql-kotlin
graviton-browser
greece
grpc
gsoc
gui
hackathons
hacktoberfest
hamburg
hamkrest
helios
helsinki
hexagon
hibernate
hikari-cp
hire-me
hiring
hongkong
hoplite
http4k
hungary
hyderabad
image-processing
india
indonesia
inkremental
intellij
intellij-plugins
intellij-tricks
internships
introduce-yourself
io
ios
iran
israel
istanbulcoders
italian
jackson-kotlin
jadx
japanese
jasync-sql
java-to-kotlin-refactoring
javadevelopers
javafx
javalin
javascript
jdbi
jhipster-kotlin
jobsworldwide
jpa
jshdq
juul-libraries
jvm-ir-backend-feedback
jxadapter
k2-early-adopters
kaal
kafka
kakao
kalasim
kapt
karachi
karg
karlsruhe
kash_shell
kaskade
kbuild
kdbc
kgen-doc-tools
kgraphql
kinta
klaxon
klock
kloudformation
kmdc
kmm-español
kmongo
knbt
knote
koalaql
koans
kobalt
kobweb
kodein
kodex
kohesive
koin
koin-dev
komapper
kondor-json
kong
kontent
kontributors
korau
korean
korge
korim
korio
korlibs
korte
kotest
kotest-contributors
kotless
kotlick
kotlin-asia
kotlin-beam
kotlin-by-example
kotlin-csv
kotlin-data-storage
kotlin-foundation
kotlin-fuel
kotlin-in-action
kotlin-inject
kotlin-latam
kotlin-logging
kotlin-multiplatform-contest
kotlin-mumbai
kotlin-native
kotlin-pakistan
kotlin-plugin
kotlin-pune
kotlin-roadmap
kotlin-samples
kotlin-sap
kotlin-serbia
kotlin-spark
kotlin-szeged
kotlin-website
kotlinacademy
kotlinbot
kotlinconf
kotlindl
kotlinforbeginners
kotlingforbeginners
kotlinlondon
kotlinmad
kotlinprogrammers
kotlinsu
kotlintest
kotlintest-devs
kotlintlv
kotlinultimatechallenge
kotlinx-datetime
kotlinx-files
kotlinx-html
kotrix
kotson
kovenant
kprompt
kraph
krawler
kroto-plus
ksp
ktcc
ktfmt
ktlint
ktor
ktp
kubed
kug-leads
kug-torino
kvision
kweb
lambdaworld_cadiz
lanark
language-evolution
language-proposals
latvia
leakcanary
leedskotlinusergroup
lets-have-fun
libgdx
libkgd
library-development
lincheck
linkeddata
lithuania
london
losangeles
lottie
love
lychee
macedonia
machinelearningbawas
madrid
malaysia
mathematics
meetkotlin
memes
meta
metro-detroit
mexico
miami
micronaut
minnesota
minutest
mirror
mockk
moko
moldova
monsterpuzzle
montreal
moonbean
morocco
motionlayout
mpapt
mu
multiplatform
mumbai
munich
mvikotlin
mvrx
myndocs-oauth2-server
naming
navigation-architecture-component
nepal
new-mexico
new-zealand
newname
nigeria
nodejs
norway
npm-publish
nyc
oceania
ohio-kotlin-users
oldenburg
oolong
opensource
orbit-mvi
osgi
otpisani
package-search
pakistan
panamá
pattern-matching
pbandk
pdx
peru
philippines
phoenix
pinoy
pocketgitclient
polish
popkorn
portugal
practical-functional-programming
proguard
prozis-android-backup
pyhsikal
python
python-contributors
quasar
random
re
react
reaktive
realm
realworldkotlin
reductor
reduks
redux
redux-kotlin
refactoring-to-kotlin
reflect
refreshversions
reports
result
rethink
revolver
rhein-main
rocksdb
romania
room
rpi-pico
rsocket
russian
russian_feed
russian-kotlinasfirst
rx
rxjava
san-diego
science
scotland
scrcast
scrimage
script
scripting
seattle
serialization
server
sg-user-group
singapore
skia-wasm-interop-temp
skrape-it
slovak
snake
sofl-user-group
southafrica
spacemacs
spain
spanish
speaking
spek
spin
splitties
spotify-mobius
spring
spring-security
squarelibraries
stackoverflow
stacks
stayhungrystayfoolish
stdlib
stlouis
strife-discord-lib
strikt
students
stuttgart
sudan
swagger-gradle-codegen
swarm
sweden
swing
swiss-user-group
switzerland
talking-kotlin
tallinn
tampa
teamcity
tegal
tempe
tensorflow
terminal
test
testing
testtestest
texas
tgbotapi
thailand
tornadofx
touchlab-tools
training
tricity-kotlin-user-group
trójmiasto
truth
tunisia
turkey
turkiye
twitter-feed
uae
udacityindia
uk
ukrainian
uniflow
unkonf
uruguay
utah
uuid
vancouver
vankotlin
vertx
videos
vienna
vietnam
vim
vkug
vuejs
web-mpp
webassembly
webrtc
wimix_sentry
wwdc
zircon
Powered by
Title
d

Dron Bhattacharya

02/25/2023, 2:16 PM
I am not familiar with testing. So I want to learn more in depth about this. For that I need help and guidance. Note: I am doing tests with Kotlin for the first time. I have not done testing in other languages before. This is what I know (What I have already done): • https://www.jetbrains.com/help/idea/tdd-with-kotlin.htmlhttps://kotlinlang.org/docs/jvm-test-using-junit.html (I have followed this) • I have seen few blogs on Mockk an Mokito. • I have seen that JUnit is present in Gradle project by default Problems: when to use what, why to choose one over the other, cannot understand how to customize related stuff in the IDEA IDE, etc
c

CLOVIS

02/25/2023, 3:26 PM
Welcome to the world of testing! Many approaches exist, and no one agrees on which are the best. When it comes to test frameworks for Kotlin, my experience is that the only two viable options are either
kotlin.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 deploying
d

Dron Bhattacharya

02/25/2023, 4:35 PM
I was having another problem. I am not able to configure Gradle as I mostly rely on the project generated by the IDEA. I don't even understand what to configure and why. I was going through the Kotest website and felt like I should be knowing more about Gradle. Can you refer me any resource for this purpose?
https://kotest.io/docs/framework/testing-styles.html And I read this. So, before I write any test, is there any theoretical aspect I have to learn
c

CLOVIS

02/25/2023, 4:37 PM
Ahah I had the same problem. Which platforms are you targetting?
d

Dron Bhattacharya

02/25/2023, 4:37 PM
Are you talking in Gradle context?
c

CLOVIS

02/25/2023, 4:38 PM
At the start of your build.gradle file, which Kotlin plugin are you using?
kotlin("jvm")
,
kotlin("js")
,
kotlin("multiplatform")
, etc
Or are you starting a new project from scratch?
In any case, I recommend starting to play with Kotest using one of their example repositories: https://github.com/orgs/kotest/repositories?q=example&type=all&language=&sort= This way, you're sure everything is configured well, and you can take inspiration from the configuration later when you start using it in a real project
d

Dron Bhattacharya

02/25/2023, 4:45 PM
@CLOVIS
kotlin("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
.
My build.gradle file (from a practice project)
/*
 * 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
.
c

CLOVIS

02/25/2023, 4:59 PM
First, you can't add multiple
kotlin()
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 opinion
Yep, your setup looks good for a JVM project. I recommend you use it to get familiar with Kotlin, so you can attempt something else later. If you have trouble with Kotest specifically, you can ask in #kotest
d

Dron Bhattacharya

02/25/2023, 5:02 PM
Is there anything to explore in the gradle setup? (from a customization prospective)
h

Humphrey

02/25/2023, 6:49 PM
I usually work with spring boot and I generate my gradle projects from start.spring.io website. You can start building and running without much knowledge of gradle.
m

Marit van Dijk

02/27/2023, 5:52 AM
If you use IntelliJ IDEA Ultimate you can do this from the IDE (the Spring support is integrated)