cascap.blogg.se

Kotlin for each with index
Kotlin for each with index




Your RunCucumberTest.kt class should now look like this: package hellocucumber If you are using IntelliJ, it will offer to translate the Java code to Kotlin code.

  • Copy the annotations from the RunCucumberTest.java class to the RunCucumberTest.kt class.
  • IntelliJ might tell you that Kotlin is not configured click “Configure”.

    kotlin for each with index

    Create a Kotlin class called RunCucumberTest inside the hellocucumber package.Create the hellocucumber package inside the kotlin directory.In IntelliJ, you can do so by right-clicking on the kotlin directory and selecting “Mark Directory as” > “Test Sources Root”. Add a directory named kotlin in your src/test directory and mark it as Test Sources Root.

    kotlin for each with index

    To use Kotlin, we need to add it to our project: Ĭhange into the directory that was just created by running the following command: cd hellocucumber You should get something like the following result: Project created from Archetype in dir: /cucumber "-DarchetypeArtifactId=cucumber-archetype" \ Open a terminal, go to the directory where you want to create your project,Īnd run the following command: mvn archetype:generate \ This example is being shown just for learning purposes, no one would normally decide to use any of these methods considering that we can use take or drop instead.We’ll start by creating a new project directory with the cucumber-archetype We have to remember that Kotlin collections indexes start from zero, that’s why we check for index 4 in the boundaries.

    kotlin for each with index

    We have implemented both take and drop by checking that the index is below or above 4.

    kotlin for each with index

    `should take first five elements`() ĪssertThat(filtered).containsExactly(10, 7, 3, 33) For example, we’re taking the first five elements in our test below. The first method we’re going to look at is take, we can use this method when we need to take just the first n elements. Photo by John Cameron on Unsplash Kotlin take()






    Kotlin for each with index