divinenickname / utgen-kotlin-core

This is a library designed to generate unit tests for Kotlin language. Simplify your testing process with automated test generation tailored for Kotlin codebases.
Apache License 2.0
3 stars 0 forks source link

Incorrect test class when source file contains multiple classes #31

Closed divinenickname closed 5 months ago

divinenickname commented 5 months ago

We can store different classes in same file using Kotlin. But our lib is working incorrect in this case.

Source class:

package com.example.demo1

class FizzClass {
    fun fizz(): Boolean = false
}

class BuzzClass {
    fun buzz(): Int = 4
}

Generated class:

package com.example.demo1

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

internal class FizzClassTest {
    @Test
    fun fizz_isTrue() {
        val obj = FizzClass()

        val actual = obj.fizz()

        Assertions.assertTrue(actual)
    }

    @Test
    fun fizz_isFalse() {
        val obj = FizzClass()

        val actual = obj.fizz()

        Assertions.assertFalse(actual)
    }

    @Test
    fun buzzTest() {
        val obj = FizzClass()

        val expected: Int = TODO('Add value here')
        val actual = obj.buzz()

        Assertions.assertEquals(expected, actual)
    }
}

buzzTest - should be in another test class

Nowadays I don't know what library should generate, but this behaviour is incorrect.