Search code examples
kotlincucumberbddcucumber-jvm

Cucumber Registering Parameter Type in Kotlin


I want to register an object instead of a Double. I looked around on the Cucumber website and implemented their way but didn't work

https://cucumber.io/docs/cucumber/configuration/?lang=kotlin#type-registry

how can this be done? here is the scenario

  Scenario: Successful withdrawal from an account in credit
    Given I have deposited a $100.00 in my account
    When I request $20
    Then $20 should be dispensed

Here is the step definition


    @Given("I have deposited a \${money} in my account")
    fun `I have deposited a $ in my account`(int1: Money) {
        account = Account()
        account.deposit(amount = int1)
        //This will be moved later to a UNIT testing and removed from cucumber.
        assertEquals(int1, account.getBalance(), "Incorrect Account Balance")
    }

I'm using Cucumber 7.8.1

how can this be done?


Solution

  • okey, the whole issue was about the {money} parameter, it should match the class name Money, also for the ParamterType

       @ParameterType(name = "Money", value = ".*")
        fun `Convert String to Money`(money: String): Money {
            val str = money.split('.').map { it.toInt() }
            return Money(dollars = str.first(), cents = str.last())
        }
    

    once I changed it to @Given("I have deposited a \${Money} in my account") it worked. but I still have the steps in the feature file the same, it says that they aren't defined despite that they run the Cucumber test class.

    but that doesn't matter it is working now.