TestNG support in kotlin.test #KT-22620

This commit is contained in:
Valeriy Zhirnov
2018-01-31 20:29:56 +03:00
committed by Ilya Gorbunov
parent 1e567438a2
commit ad7701922c
7 changed files with 137 additions and 0 deletions
+39
View File
@@ -0,0 +1,39 @@
description = 'Kotlin Test TestNG'
apply plugin: 'kotlin-platform-jvm'
configureJvm6Project(project)
configurePublishing(project)
dependencies {
expectedBy project(':kotlin-test:kotlin-test-annotations-common')
compile project(':kotlin-test:kotlin-test-jvm')
compile('org.testng:testng:6.13.1')
}
jar {
manifestAttributes(manifest, project, 'Test')
}
artifacts {
archives sourcesJar
archives javadocJar
}
dist {
from (jar, sourcesJar)
}
compileKotlin {
kotlinOptions.freeCompilerArgs = ["-Xallow-kotlin-package", "-Xmulti-platform", "-module-name", project.name]
}
compileTestKotlin {
kotlinOptions.freeCompilerArgs = ["-Xallow-kotlin-package"]
}
test {
useTestNG()
}
@@ -0,0 +1,14 @@
/*
* Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the license/LICENSE.txt file.
*/
@file:Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE")
@file:JvmPackageName("kotlin.test.annotations")
package kotlin.test
public actual typealias Test = org.testng.annotations.Test
public actual typealias Ignore = org.testng.annotations.Ignore
public actual typealias BeforeTest = org.testng.annotations.BeforeClass
public actual typealias AfterTest = org.testng.annotations.AfterClass
@@ -0,0 +1,55 @@
/*
* Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the license/LICENSE.txt file.
*/
package kotlin.test.testng
import org.testng.*
import kotlin.test.*
class TestNGContributor : AsserterContributor {
override fun contribute(): Asserter? {
for (stackFrame in currentStackTrace()) {
val className = stackFrame.className
if (className.startsWith("org.testng.") || className.startsWith("testng.")) {
return TestNGAsserter
}
}
return null
}
}
object TestNGAsserter : Asserter {
override fun assertEquals(message : String?, expected : Any?, actual : Any?) {
Assert.assertEquals(expected, actual, message)
}
override fun assertNotEquals(message : String?, illegal : Any?, actual : Any?) {
Assert.assertNotEquals(illegal, actual, message)
}
override fun assertSame(message : String?, expected : Any?, actual : Any?) {
Assert.assertSame(expected, actual, message)
}
override fun assertNotSame(message : String?, illegal : Any?, actual : Any?) {
Assert.assertNotSame(illegal, actual, message)
}
override fun assertNotNull(message : String?, actual : Any?) {
Assert.assertNotNull(actual, message ?: "actual value is null")
}
override fun assertNull(message : String?, actual : Any?) {
Assert.assertNull(actual, message ?: "actual value is not null")
}
override fun fail(message : String?): Nothing {
Assert.fail(message)
// should not get here
throw AssertionError(message)
}
}
@@ -0,0 +1 @@
kotlin.test.testng.TestNGContributor
@@ -0,0 +1,25 @@
package kotlinx.testing.tests
import org.testng.annotations.*
import org.testng.*
import java.util.concurrent.*
class TestNGContributorTest {
@Test
fun smokeTest() {
Assert.assertEquals("TestNGAsserter", kotlin.test.asserter.javaClass.simpleName)
}
@Test
fun `should fail to contribute if it was run outside of testng`() {
val q = ArrayBlockingQueue<Any>(1)
Thread {
q.put(kotlin.test.asserter)
}.start()
Assert.assertEquals("DefaultAsserter", q.take().javaClass.simpleName)
}
}