# How to create a parameterized base test class in Kotlin

DevFeed: [How to create a parameterized base test class in Kotlin](<https://devfeed.tech/articles/how-to-create-a-parameterized-base-test-class-in-kotlin-25575.md>)

Original publisher: [Read original article](<https://www.marcogomiero.com/posts/2023/parameterized-kotlin-base-test/>)

Author: Marco Gomiero

Published: 2023-01-31T00:00:00Z

Content type: tutorial

Language: en

Sources: [Posts on Marco Gomiero](<https://devfeed.tech/sources/posts-on-marco-gomiero.md>)

Topics: [table driven tests](<https://devfeed.tech/topics/table-driven-tests.md>), [test data](<https://devfeed.tech/topics/test-data.md>), [class](<https://devfeed.tech/topics/class.md>), [superclass](<https://devfeed.tech/topics/superclass.md>)

Tags: [arguments](<https://devfeed.tech/tags/arguments.md>), [base](<https://devfeed.tech/tags/base.md>), [companion](<https://devfeed.tech/tags/companion.md>), [constructor](<https://devfeed.tech/tags/constructor.md>), [environment](<https://devfeed.tech/tags/environment.md>), [how-to](<https://devfeed.tech/tags/how-to.md>), [junit](<https://devfeed.tech/tags/junit.md>), [kotlin](<https://devfeed.tech/tags/kotlin.md>), [runner](<https://devfeed.tech/tags/runner.md>), [tests](<https://devfeed.tech/tags/tests.md>)

## AI overview

JUnit 4's Parameterized runner injects test arguments through the test class constructor, with the argument set defined in that class's companion object. For tests that need shared setup, the text describes making a base test class accept an argument and define the required arguments in its companion object; concrete test classes then extend the base class, use the runner, and pass the argument to the base-class constructor. This enables the same tests to run across multiple inputs with shared configuration. The excerpt focuses on JUnit 4, though it notes JUnit 5 also offers parameterized tests.

## Source excerpt

One exciting feature of JUnit 4 (and 5 as well, but this post will be focused on JUnit 4) is the possibility of running the same test with different input arguments. That is made possible by a custom test runner called Parameterized, which will inject the provided arguments in the constructor of the test class. Instead, the different arguments must be defined in the companion object of the test class.