Lazy variable evaluation for test in Kotlin

givenK

Lazy variable evaluation for test in Kotlin (inspired by Given2) givenK

Installation

Step 1. Add the JitPack repository to your build file

allprojects {
    repositories {
        ...
        maven { url 'https://jitpack.io' }
    }
}

Step2. Add the dependency

dependencies {
    implementation 'com.github.JIY0UNG:givenK:Tag'
}

Usage

class MyTest {
    var foo by Given { "" }

    @Nested
    @DisplayName("When nothing given")
    inner class Test1 {
    
        @Test
        @DisplayName("foo should be empty String")
        fun test() {
            assertEquals("", foo)
        }
    }

    @Nested
    @DisplayName("When \"Hello World\" given")
    inner class Test2 {
    
        @BeforeEach
        fun setUp() {
            foo = "Hello World"
        }

        @Test
        @DisplayName("foo should be \"Hello World\"")
        fun test() {
            assertEquals("Hello World", foo)
        }
    }
}

GitHub

View Github