Skip to content

This is a library designed to generate unit tests for Kotlin language. Simplify your testing process with automated test generation tailored for Kotlin codebases.

License

Notifications You must be signed in to change notification settings

divinenickname/utgen-kotlin-core

Repository files navigation

GitHub license main branch build Maven metadata URL Maven Central Version codecov Coverage

Logo image. Red circle with letter U inside.

UTGen-core

A small library for generating UNIT tests for the Kotlin language. Save time with the code generator by focusing more on truly important matters. The library covers common scenarios and generates test cases based on your code. All you need to do is provide the expected value.

Features

  • Default case with return value
  • Default case for 'Unit' value
  • Nullable return types case
  • Primitives test case
  • Boolean true/false cases

How to

Add dependency:

implementation("io.github.divinenickname.kotlin.utgen:utgen-core:1.3.1")

After that you can start generating test using two simple methods:

UnitTestGenerator()
    .generateAndSave("path/to/kotlin/Class.kt")

OR

UnitTestGenerator()
    .generate("path/to/kotlin/Class.kt")
    .writeTo(file or path)

Example

Your source class is:

package com.example.demo1

class MyTestClass {

    fun nonVoid(): ObjClass {
        return ObjClass()
    }
}

Library generates code:

package com.example.demo1

import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.Test

internal class MyTestClassTest {
  @Test
  public fun nonVoidTest() {
    val obj = MyTestClass()

    val expected = ObjClass()
    val actual = obj.nonVoid()

    Assertions.assertEquals(expected, actual)
  }
}

See more at: EXAMPLES.md

Depends on

See also

hi!

About

This is a library designed to generate unit tests for Kotlin language. Simplify your testing process with automated test generation tailored for Kotlin codebases.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published