Configure parallel tests with Kotlin - Amazon CodeBuild
Services or capabilities described in Amazon Web Services documentation might vary by Region. To see the differences applicable to the China Regions, see Getting Started with Amazon Web Services in China (PDF).

Configure parallel tests with Kotlin

The following is sample of a buildspec.yml that shows parallel test execution with Kotlin on an Linux platform:

version: 0.2 batch: fast-fail: false build-fanout: parallelism: 2 ignore-failure: false phases: install: runtime-versions: java: corretto11 commands: - echo 'Installing dependencies' - KOTLIN_VERSION="1.8.20" # Replace with your desired version - curl -o kotlin-compiler.zip -L "https://github.com/JetBrains/kotlin/releases/download/v${KOTLIN_VERSION}/kotlin-compiler-${KOTLIN_VERSION}.zip" - unzip kotlin-compiler.zip -d /usr/local - export PATH=$PATH:/usr/local/kotlinc/bin - kotlin -version - curl -O https://repo1.maven.org/maven2/org/junit/platform/junit-platform-console-standalone/1.8.2/junit-platform-console-standalone-1.8.2.jar pre_build: commands: - echo 'prebuild' build: commands: - echo 'Running Kotlin Tests' - | codebuild-tests-run \ --test-command 'kotlinc src/main/kotlin/*.kt $(echo "$CODEBUILD_CURRENT_SHARD_FILES" | tr "\n" " ") -d classes -cp junit-platform-console-standalone-1.8.2.jar' \ --files-search "codebuild-glob-search 'src/test/kotlin/*.kt'" - | codebuild-tests-run \ --test-command ' java -jar junit-platform-console-standalone-1.8.2.jar --class-path classes \ $(for file in $CODEBUILD_CURRENT_SHARD_FILES; do class_name=$(basename "$file" .kt) echo "--select-class $class_name" done) ' \ --files-search "codebuild-glob-search 'src/test/kotlin/*.kt'" post_build: commands: - echo "Test execution completed"

In the above example, the codebuild-tests-run CLI is used twice. During the first run, kotlinc compiles the files. The CODEBUILD_CURRENT_SHARD_FILES variable retrieves the test files assigned to the current shard, which are then converted into a space-separated list. In the second run, JUnit executes the tests. Again, CODEBUILD_CURRENT_SHARD_FILES fetches the test files assigned to the current shard, but this time they are converted into class names.