Skip to content

Latest commit

 

History

History
86 lines (66 loc) · 2.51 KB

README.md

File metadata and controls

86 lines (66 loc) · 2.51 KB

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!