Skip to content

Latest commit

 

History

History
162 lines (129 loc) · 3.76 KB

allure.md

File metadata and controls

162 lines (129 loc) · 3.76 KB

kTest :: Integration :: Allure

Download

Gradle

'run.smt.ktest:ktest-allure'

Maven

<dependency>
    <groupId>run.smt.ktest</groupId>
    <artifactId>ktest-allure</artifactId>
</dependency>

Description

Provides integration with Allure reporting framework

Providing meta-information

import run.smt.ktest.specs.BehaviorSpec
import run.smt.ktest.allure.*

class SomeSpec : BehaviorSpec({
    given("a service", metaInfo = {
        epic("my service")
    }) {
        `when`("something happens", metaInfo = {
            feature("my feature")
            story("my story")
        }) {
            then("do something", metaInfo = {
                muted()
                severity(critical)
                title("my test case")
                description("""
                    My long and verbose description
                """.trimIndent())
                
                issue("MYISS-1")
                // for more meta-info see IDEAs help on Ctrl+Space for `this.`
            }) {
                "my step" step {
                    // do something
                }
                
                // alternative step DSL
                { /* do something else */ } namely "my other step"
                
                // verbose steps:
                step(
                    name = "yet another step",
                    description = """
                        Verbose description for step
                        """.trimIndent(),
                    parameters = *arrayOf(
                        "firstParam" to 1,
                        "secondParam" to "hello"
                    )
                ) {
                    // code
                }
            }
        }
    }
})

Attachments

import run.smt.ktest.allure.*

fun somewhereInCode(fileContent: Any) {
    attach(
        name = "my file",
        value = fileContent, // non-stringish values will be dumped as json
        type = "x-application/my-file",
        extension = ".f"
    )
    
    // short form:
    
    attach(fileContent to "my file")
}

Logging

Logs that will be available as attachments

import run.smt.ktest.specs.*
import run.smt.ktest.allure.*

class MySpec1 : BehaviorSpec({
    val log = autoClose(logger())
                
    log.write("hello!")
    log.dump(someObject) // will be written as prettified JSON
    
    // logging to specific file
    
    val result = logsTo("myLogFile") {
        write("hello!")
        dump(someObject)
    }
})

AllureSpec

import run.smt.ktest.specs.AllureSpec
import run.smt.ktest.allure.*

class MySpec2 : AllureSpec({
    epic("my service") {
        feature("my feature", metaInfo = { owner("someone") }) {
            story("my story") {
                case("my test case", metaInfo = {
                    muted()
                    severity(critical)
                    description("""
                        My long and verbose description
                    """.trimIndent())
                    
                    issue("MYISS-1")
                }) {
                    // test body
                }
            }
        }
    }
    
    // if you hate ladders of code like me, you can use something like this:
    
    val suite = epic("My epic") + feature("feature")
    
    suite(metaInfo = {
        // you can also provide meta info
    }) {
        story("my story") { // you can nest not defined parts!
            case("my case") {
                // test
            }
        }
        
        epic("I want this code to be in another epic") { // end even override!
            (story("some story") + case("case")) { // and even such madness is OK!
                // test body
            }
        }
    }
})