Skip to content

iankurrathi/lsd-kotlin-cucumber-example

 
 

Repository files navigation

lsd-kotlin-cucumber-example

This is a demo project to showcase the LSD library with Cucumber in Kotlin.

To view an example report please go here: https://lsd-consulting.github.io/lsd-kotlin-cucumber-example/lsd-index.html

When applying LSD and Cucumber it is easy to produce a diagram like this from tests:

Diagram example

Here is the Gherkin script used for the above diagram:

Feature: Find activity

  Scenario: find an activity by id
    Given an existing activity with lessonId ABC
    When the activity is requested by its id
    Then the activity with lessonId ABC is returned

How to add LSD to a project with existing Cucumber/Gherkin scripts

  1. Add the following test dependencies:
componentTestImplementation("io.github.lsd-consulting:lsd-cucumber:+")
componentTestImplementation("io.github.lsd-consulting:lsd-interceptors:+")
  1. Include the LSD Cucumber plugin, for example by setting the cucumber.plugin property in the junit-platform.properties file:
cucumber.plugin=lsd.cucumber.LsdCucumberPlugin

NOTE Currently, LSD doesn't support parallel test execution yet, so do not change the value of the cucumber.execution.parallel.enabled property to true. Keep the default value which is false.

  1. Import the following Spring config file in the tests:
@Import(SpringBridge::class)
@Configuration
class SequenceDiagramConfig {

    @Bean
    fun testState(): TestState {
        return TestState()
    }

    @Bean
    fun httpInterceptorHandlers(): List<HttpInteractionHandler> {
        return listOf(
                DefaultHttpInteractionHandler(
                        testState(),
                        userSuppliedSourceMappings(mapOf("/" to "ComponentTest")),
                        userSuppliedDestinationMappings(mapOf("/" to "App")))
        )
    }

    @Bean
    fun participants(): List<Participant> {
        return listOf(
                Participants.ACTOR.create("User"),
                Participants.PARTICIPANT.create("App", "Activity Engine")
        )
    }
}

The above is a standard LSD setup. Further details on it can be found here

To import the above file add this annotation to the Spring based test:

@Import(SequenceDiagramConfig::class)
  1. It's also helpful to generate the diagrams in a local folder rather than the default one. This can be done by setting the lsd.core.report.outputDir property, for example like this:
tasks.withType<Test> {
    systemProperty("lsd.core.report.outputDir", "$buildDir/reports/lsd")
}

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Kotlin 91.8%
  • Gherkin 8.2%