Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Mocking creates uncompilable code for Kotlin, due improper mockedConstruction type #1278

Open
Labels
ctg-bugIssue is a bug lang-kotlinIssue is related to Kotlin language support
@tyuldashev

Description

Description

When user tries to use mocking for external classes UTBot creates var mockedConstruction = null which usage in the code cause type compatibility errors

To Reproduce

Steps to reproduce the behavior:

  1. In UTBot settings set Generated test language to Kotlin other leave default
  2. Enable Force mocking static methods
  3. Generate tests for following code
import java.util.Random
class RandomInt {
 fun multByRandom(x: Int): Int {
 val random: Random = Random();
 return x * random.nextInt();
 }
}

Expected behavior

Compilable code is generated

Actual behavior

Generated test cannot be compiled. See its beginning below.

 @Test
 fun testMultByRandom1() {
 var mockedConstruction = null
 try {
 val mockClassCounter = AtomicInteger()
 mockedConstruction = mockConstruction(Random::class.java) { RandomMock: Random,
 context: MockedConstruction.Context
 -> when (mockClassCounter.get()) {
 0 -> {
 (`when`(RandomMock.nextInt())).thenReturn(0)
 }
 }
 mockClassCounter.getAndIncrement()
 }

Visual proofs (screenshots, logs, images)

image

Metadata

Metadata

Labels

ctg-bugIssue is a bug lang-kotlinIssue is related to Kotlin language support

Type

No type

Projects

Status

Todo

Milestone

No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      AltStyle によって変換されたページ (->オリジナル) /