Git Product home page Git Product logo

kotlinunittesting's Introduction

Kotlin Unit Testing Examples

This repository contains examples of basic unit tests written in Kotlin. In specific directories you can find gradle buildscript with needed dependencies and configuration, simple unit test and parameterized test.

All sample projects was verified under Gradle 4.10.2 and Intellij IDEA 2018.2.4

Application

UseCase which provides empty string - to showcase structure of test methods

DistanceConverter - converts meters to kilometers in parameterized tests

MVP - Model-View-Presenter contract

Gradle, Kotlin & Groovy

This Gradle project is by default configured with Gradle’s Kotlin DSL

The equivalent Groovy build are still available for you copy&pasting pleasures, they have been renamed as build.gradle.groovy

You can switch between Groovy and Kotlin by running the script $ ./toggle-kotlin-groovy.sh

Junit4

Attach to project

dependencies{
    testCompile group: 'junit', name: 'junit', version: '4.12'
}

Junit5

Attach to project

dependencies {
    testCompile('org.junit.jupiter:junit-jupiter-api:5.3.1')
    testCompile('org.junit.jupiter:junit-jupiter-params:5.3.1')
    testRuntime('org.junit.jupiter:junit-jupiter-engine:5.3.1')
}

test {
    useJUnitPlatform()
    testLogging {
        events "passed", "skipped", "failed"
    }
}

KotlinTest

Attach to project

dependencies{
    testCompile 'io.kotlintest:kotlintest-runner-junit5:3.1.10'
}

Spek

Attach to project

repositories {
    mavenCentral()
    maven { url "https://dl.bintray.com/spekframework/spek-dev" }

}

test {
    useJUnitPlatform {
        includeEngines 'spek2'
    }
}

dependencies {
    testImplementation ('org.spekframework.spek2:spek-dsl-jvm:2.0.0-rc.1')  {
        exclude group: 'org.jetbrains.kotlin'
    }
    testRuntimeOnly ('org.spekframework.spek2:spek-runner-junit5:2.0.0-rc.1') {
        exclude group: 'org.junit.platform'
        exclude group: 'org.jetbrains.kotlin'
    }

    testCompile('org.junit.jupiter:junit-jupiter-api:5.3.1')


    // spek requires kotlin-reflect, can be omitted if already in the classpath
    testRuntimeOnly "org.jetbrains.kotlin:kotlin-reflect:$kotlin_version"
}

For Spek you may also need additional Intellij or Android Studio plugin

Mockito

Add to project

repositories {
    mavenCentral()
    jcenter()
}


dependencies {
    testCompile "org.mockito:mockito-core:2.23.0"

    testCompile group: 'junit', name: 'junit', version: '4.12'
}

Mockito-Kotlin

Add to project

repositories {
    mavenCentral()
    jcenter()
}


dependencies {
    testCompile "org.mockito:mockito-core:2.23.0"
    testCompile "com.nhaarman.mockitokotlin2:mockito-kotlin:2.0.0-RC1"

    testCompile group: 'junit', name: 'junit', version: '4.12'
}

Mockk

Add to project

dependencies {
    testCompile group: 'junit', name: 'junit', version: '4.12'
    testImplementation "io.mockk:mockk:1.8.12"
}

Strikt

Add to project

dependencies {
    testImplementation("io.strikt:strikt-core:0.17.0")
}

kotlinunittesting's People

Contributors

jmfayard avatar leocolman avatar rozkminiacz avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

kotlinunittesting's Issues

New KotlinTest module for a Kotlin Academy article

Hello Jaroslaw,

I have a plan to write an article about KotlinTest for https://blog.kotlin-academy.com

I contributed to this project in the past (the asciidoc and Gradle Kotlin DSL parts), and I thought it would be handy to have the code samples I will use to be part of this project. It's a good way to have a unit tests playground already setup, and people can compare with what is available in the other unit tests frameworks.

I don't want to bother you each time I make a modification to my code samples though.

Would you mind to give me write access to this repo?

Jean-Michel Fayard

Add TestNG to samples

Create new module named testng with samples of TestNG framework usage.
testng.org/

  • Gradle and Intellij configuration
  • Unit test example
  • Parameterized test example
  • Example of test grouping

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.