Skip to content

Support Kotlin top level functions as test methods #2771

Open
@mmerdes

Description

@mmerdes

In Kotlin, functions are first class citizens and do not need the context of a class definition.
Idiomatic Kotlin often tries to avoid as much code as possible.
The current implementation of JUnit Jupiter does not allow to execute such top level functions as tests.
As Kotlin top level functions are compiled to static JVM methods with a predictable class name and an annotation identifying the generated class as a Kotlin class, it should be possible to add such support.

Complete example of tests without a class definition:

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


@Test
fun failure() = assertTrue(false)

@Test
fun success() = assertTrue(true)

Careful thought about possible limitations to life-cycle methods might be in order.

Deliverables

  • add ability to execute Kotlin top level functions as tests

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions