Can I use KotlinTest with TestNG? I can see only JUnit in the documentation.
Asked
Active
Viewed 1,956 times
2 Answers
1
Yes, you can use TestNG with Kotlin. Just configure TestNG dependency and you are good to go. It is similar to Junit. Below is a sample program for the same:
abstract class TestBase {
lateinit var driver: WebDriver
private set
@BeforeTest
fun setup() {
System.setProperty(UtilResources.getProperties("nameDriver"),
UtilResources.getProperties("pathDriver") + UtilResources.getProperties("exeDriver"))
driver = ChromeDriver()
driver?.manage()?.timeouts()?.implicitlyWait(10, TimeUnit.SECONDS)
driver?.manage()?.window()?.maximize()
driver?.get(URI(UtilResources.getProperties("pageURL")).toString())
}
@AfterTest
fun driverClose() {
driver?.close();
}
}

scls
- 16,591
- 10
- 44
- 55

Raghav Arora
- 390
- 4
- 9
-
Thank you for your answer. We are already using Kotlin with TestNG in our project. But we would like to also use [KotlinTest](https://github.com/kotlintest/kotlintest) framework on top of it. Is it possible? – Klugi Aug 07 '18 at 08:57
-
I've added an answer. Basically the answer is no. But you could continue to use both. Just run your junit tests and your testng tests. That should happen automatically in your build tool if it's configured right. – sksamuel Aug 07 '18 at 12:58
0
The answer is no. KotlinTest is built on JUnit Platform, which is a basis to allow testing libraries to integrate with things like IntelliJ and gradle, without having to themselves write plugins.
As JUnit say themselves,
The JUnit Platform serves as a foundation for launching testing frameworks on the JVM

opticyclic
- 7,412
- 12
- 81
- 155

sksamuel
- 16,154
- 8
- 60
- 108
-
Thank you for clarification. In our project, we already do have lot of tests in Java on top of TestNG, lot of common code and lot of configuration as well. For new test we are trying to use Kotlin on top of TestNG and current test code base. Everything goes fine and we really like it. If we could also incorporate KotlinTest in this ecosystem it would be another step forward. Then we could use interceptors, matchers and other cool features. But rewriting the tests and the test infrastructure we already have is not the way we could afford to take. – Klugi Aug 07 '18 at 16:35
-
I don't think TestNG has support to execute other tests as I've had a look. Open a ticket on github and we'll discuss it there. – sksamuel Aug 07 '18 at 18:57