Skip to content
Generate unit testing boilerplate from kotlin files.
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.


While TDD is a better approach for development, many projects don't practice it and end up with low test coverage.

This project is here to help you improve your test coverage by reducing the effort spent on writing boilerplate code, allowing you to focus on writing the actual tests.

Use TestIt to generate unit testing boilerplate from kotlin files.

Getting Started

While you can run ./gradlew run --args "filepath", it might be more convenient to set up a shortcut to the provided helper script:


  1. Get HomeBrew
  2. Run brew install coreutils
  3. Create a symbolic link: sudo ln -s /path/to/testit /usr/local/bin

Note: your project would need to include mockito 2 and mockito-kotlin or MockK.


One installed, running TestIt is as simple as

testit path/to/file.kt


TestIt generates a test file in the default expected path.

For example, when run against itself (testit app/src/main/java/com/mitteloupe/testit/TestIt.kt) - see source file - it generates the below file at app/src/test/java/com/mitteloupe/testit/TestItTest.kt:

package com.mitteloupe.testit

import com.mitteloupe.testit.config.PropertiesReader
import com.mitteloupe.testit.file.FileProvider
import com.mitteloupe.testit.generator.TestFilePathFormatter
import com.mitteloupe.testit.generator.TestsGeneratorFactory
import com.mitteloupe.testit.model.ClassTestCode
import com.mitteloupe.testit.parser.KotlinFileParser
import com.nhaarman.mockitokotlin2.mock
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
import org.mockito.Mock
import org.mockito.junit.MockitoJUnitRunner

class TestItTest {
    private lateinit var cut: TestIt

    lateinit var propertiesReader: PropertiesReader

    lateinit var fileProvider: FileProvider

    lateinit var kotlinFileParser: KotlinFileParser

    lateinit var testFilePathFormatter: TestFilePathFormatter

    lateinit var testsGeneratorFactory: TestsGeneratorFactory

    fun setUp() {
        cut = TestIt(propertiesReader, fileProvider, kotlinFileParser, testFilePathFormatter, testsGeneratorFactory)

    fun `Given _ when getTestsForFile then _`() {
        // Given
        val fileName = "fileName"

        // When
        val actualValue = cut.getTestsForFile(fileName)

        // Then
        TODO("Define assertions")

    fun `Given _ when saveTestsToFile then _`() {
        // Given
        val sourceFileName = "sourceFileName"
        val classTestCode = mock<ClassTestCode>()

        // When
        cut.saveTestsToFile(sourceFileName, classTestCode)

        // Then
        TODO("Define assertions")

    fun `Given _ when showHelp then _`() {
        // Given

        // When

        // Then
        TODO("Define assertions")


  • Automatically compiles a list of required imports
  • Supports multiple classes in one Kotlin file
  • Supports both mockito 2 and MockK
  • Can generate test code for abstract classes
  • Configurable


This code uses a JAR from kotlin-grammar-tools to parse Kotlin code.

Created by

Eran Boudjnah


MIT © Eran Boudjnah

You can’t perform that action at this time.