TestNG support in kotlin.test #KT-22620
This commit is contained in:
committed by
Ilya Gorbunov
parent
1e567438a2
commit
ad7701922c
@@ -223,6 +223,7 @@ val coreLibProjects = listOf(
|
||||
":kotlin-test:kotlin-test-common",
|
||||
":kotlin-test:kotlin-test-jvm",
|
||||
":kotlin-test:kotlin-test-junit",
|
||||
":kotlin-test:kotlin-test-testng",
|
||||
":kotlin-test:kotlin-test-js",
|
||||
":kotlin-reflect"
|
||||
)
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
+1
@@ -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)
|
||||
}
|
||||
|
||||
}
|
||||
@@ -97,6 +97,7 @@ include ":kotlin-build-common",
|
||||
":kotlin-test:kotlin-test-annotations-common",
|
||||
":kotlin-test:kotlin-test-jvm",
|
||||
":kotlin-test:kotlin-test-junit",
|
||||
":kotlin-test:kotlin-test-testng",
|
||||
":kotlin-test:kotlin-test-js",
|
||||
":kotlin-test:kotlin-test-js:kotlin-test-js-it",
|
||||
":kotlin-stdlib-common",
|
||||
@@ -164,6 +165,7 @@ project(':kotlin-test:kotlin-test-common').projectDir = "$rootDir/libraries/kotl
|
||||
project(':kotlin-test:kotlin-test-annotations-common').projectDir = "$rootDir/libraries/kotlin.test/annotations-common" as File
|
||||
project(':kotlin-test:kotlin-test-jvm').projectDir = "$rootDir/libraries/kotlin.test/jvm" as File
|
||||
project(':kotlin-test:kotlin-test-junit').projectDir = "$rootDir/libraries/kotlin.test/junit" as File
|
||||
project(':kotlin-test:kotlin-test-testng').projectDir = "$rootDir/libraries/kotlin.test/testng" as File
|
||||
project(':kotlin-test:kotlin-test-js').projectDir = "$rootDir/libraries/kotlin.test/js" as File
|
||||
project(':kotlin-test:kotlin-test-js:kotlin-test-js-it').projectDir = "$rootDir/libraries/kotlin.test/js/it" as File
|
||||
project(':kotlin-stdlib-common').projectDir = "$rootDir/libraries/stdlib/common" as File
|
||||
|
||||
Reference in New Issue
Block a user