Skip to content

UTBot generates uncompilable Kotlin parametrized tests #1104

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
tyuldashev opened this issue Oct 5, 2022 · 4 comments
Open

UTBot generates uncompilable Kotlin parametrized tests #1104

tyuldashev opened this issue Oct 5, 2022 · 4 comments
Assignees
Labels
comp-codegen Issue is related to code generator ctg-bug Issue is a bug lang-kotlin Issue is related to Kotlin language support

Comments

@tyuldashev
Copy link
Collaborator

Description

When user tries to generate parametrized test for Kotlin code as result she gets uncompilable code

To Reproduce

Steps to reproduce the behavior:

  1. Invoke test generation for the code below, with enabled setting Parametrized tests
class A {
    fun f(a:Int, b:Int): Int {
        return a + b;
    }
}

Expected behavior

Executable tests are generated

Actual behavior

Tests cannot be compiled and executed.

Visual proofs (screenshots, logs, images)
Resulted code and errors:

image

class ATest {
    ///region Test suites for executable org.test.A.f
    
    ///region Parameterized test for method f(int, int)
    
    @ParameterizedTest
    @MethodSource("org.test.ATest#provideDataForF")
    fun parameterizedTestsForF(a: A?,
    a1: Int,
    b: Int,
    expectedResult: Int?
    ) {
        val actual = a.f(a1, b) // #1 error
        
        assertEquals(expectedResult, actual)
    }
    ///endregion
    
    ///endregion
    
    companion object {
        ///region Data providers
        
        @JvmStatic
        fun provideDataForF(): java.util.ArrayList // #2 error
         {
            val argList = java.util.ArrayList() // #3 error
            
            run {
                val a = A()
                
                val testCaseObjects = kotlin.Array<Any?>(4) { null }
                testCaseObjects[0] = a
                testCaseObjects[1] = -1
                testCaseObjects[2] = 1
                testCaseObjects[3] = 0
                argList.add(arguments(testCaseObjects))
            }
            
            return argList
        }
        ///endregion
    }
}
@tyuldashev tyuldashev added ctg-bug Issue is a bug comp-codegen Issue is related to code generator labels Oct 5, 2022
@tyuldashev tyuldashev moved this to Todo in UTBot Java Oct 5, 2022
@volivan239
Copy link
Collaborator

volivan239 commented Oct 5, 2022

I believe this is a part of two much bigger issues related to Kotlin type system with its generics (#88) and nullability (no specific issue made yet afaik) and ideally should be fixed after solving those two (thus, this is an important case on which they should be tested)

@EgorkaKulikov
Copy link
Collaborator

Parametrized tests are not supported for Kotlin and their support was never declared. In fact, sometimes they really work, but this is just a good luck.
The comment of Vanya explains the reasons.

@tyuldashev
Copy link
Collaborator Author

I think that in any case UTBot should not generate uncompilable code. Otherwise user would have to remove/fix such tests based on no information before she could use generated tests. That could become especially inconvenient in case tests have been generated for the whole project or package.

@alisevych alisevych added this to the 2022.12 Release milestone Oct 7, 2022
@tyuldashev tyuldashev added the lang-kotlin Issue is related to Kotlin language support label Oct 28, 2022
@EgorkaKulikov
Copy link
Collaborator

@alisevych Currently parameterized tests are disabled for Kotlin, we will enable it again after further Kotlin support. I think we should remove this task from 2022.12 Release.

@alisevych alisevych removed this from the 2022.12 Release milestone Nov 21, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
comp-codegen Issue is related to code generator ctg-bug Issue is a bug lang-kotlin Issue is related to Kotlin language support
Projects
Status: Todo
Development

No branches or pull requests

5 participants