Specify test framework to use explicitly in generate test tests
This commit is contained in:
+15
-3
@@ -127,11 +127,23 @@ abstract class KotlinGenerateTestSupportActionBase(
|
|||||||
|
|
||||||
override fun invoke(project: Project, editor: Editor, file: PsiFile) {
|
override fun invoke(project: Project, editor: Editor, file: PsiFile) {
|
||||||
val klass = findTargetClass(editor, file) ?: return
|
val klass = findTargetClass(editor, file) ?: return
|
||||||
val frameworks = findSuitableFrameworks(klass)
|
|
||||||
.filter { methodKind.getFileTemplateDescriptor(it) != null && isApplicableTo(it, klass) }
|
if (testFrameworkToUse != null) {
|
||||||
chooseAndPerform(editor, frameworks) { doGenerate(editor, file, klass, it) }
|
val frameworkToUse = findSuitableFrameworks(klass).first { it.name == testFrameworkToUse }
|
||||||
|
if (isApplicableTo(frameworkToUse, klass)) {
|
||||||
|
doGenerate(editor, file, klass, frameworkToUse)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
val frameworks = findSuitableFrameworks(klass)
|
||||||
|
.filter { methodKind.getFileTemplateDescriptor(it) != null && isApplicableTo(it, klass) }
|
||||||
|
|
||||||
|
chooseAndPerform(editor, frameworks) { doGenerate(editor, file, klass, it) }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var testFrameworkToUse: String? = null
|
||||||
|
|
||||||
private val DUMMY_NAME = "__KOTLIN_RULEZZZ__"
|
private val DUMMY_NAME = "__KOTLIN_RULEZZZ__"
|
||||||
|
|
||||||
private fun doGenerate(editor: Editor, file: PsiFile, klass: KtClassOrObject, framework: TestFramework) {
|
private fun doGenerate(editor: Editor, file: PsiFile, klass: KtClassOrObject, framework: TestFramework) {
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
// ACTION_CLASS: org.jetbrains.kotlin.idea.actions.generate.KotlinGenerateTestSupportActionBase$Data
|
// ACTION_CLASS: org.jetbrains.kotlin.idea.actions.generate.KotlinGenerateTestSupportActionBase$Data
|
||||||
// CONFIGURE_LIBRARY: JUnit@lib/junit-4.12.jar
|
// CONFIGURE_LIBRARY: JUnit@lib/junit-4.12.jar
|
||||||
|
// TEST_FRAMEWORK: JUnit4
|
||||||
class A {<caret>
|
class A {<caret>
|
||||||
|
|
||||||
}
|
}
|
||||||
+1
@@ -2,6 +2,7 @@ import org.junit.runners.Parameterized
|
|||||||
|
|
||||||
// ACTION_CLASS: org.jetbrains.kotlin.idea.actions.generate.KotlinGenerateTestSupportActionBase$Data
|
// ACTION_CLASS: org.jetbrains.kotlin.idea.actions.generate.KotlinGenerateTestSupportActionBase$Data
|
||||||
// CONFIGURE_LIBRARY: JUnit@lib/junit-4.12.jar
|
// CONFIGURE_LIBRARY: JUnit@lib/junit-4.12.jar
|
||||||
|
// TEST_FRAMEWORK: JUnit4
|
||||||
class A {
|
class A {
|
||||||
@Parameterized.Parameters
|
@Parameterized.Parameters
|
||||||
fun data(): Collection<Array<Any>> {
|
fun data(): Collection<Array<Any>> {
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
// ACTION_CLASS: org.jetbrains.kotlin.idea.actions.generate.KotlinGenerateTestSupportActionBase$SetUp
|
// ACTION_CLASS: org.jetbrains.kotlin.idea.actions.generate.KotlinGenerateTestSupportActionBase$SetUp
|
||||||
// CONFIGURE_LIBRARY: JUnit@lib/junit-4.12.jar
|
// CONFIGURE_LIBRARY: JUnit@lib/junit-4.12.jar
|
||||||
|
// TEST_FRAMEWORK: JUnit4
|
||||||
class A {<caret>
|
class A {<caret>
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -2,6 +2,7 @@ import org.junit.Before
|
|||||||
|
|
||||||
// ACTION_CLASS: org.jetbrains.kotlin.idea.actions.generate.KotlinGenerateTestSupportActionBase$SetUp
|
// ACTION_CLASS: org.jetbrains.kotlin.idea.actions.generate.KotlinGenerateTestSupportActionBase$SetUp
|
||||||
// CONFIGURE_LIBRARY: JUnit@lib/junit-4.12.jar
|
// CONFIGURE_LIBRARY: JUnit@lib/junit-4.12.jar
|
||||||
|
// TEST_FRAMEWORK: JUnit4
|
||||||
class A {
|
class A {
|
||||||
@Before
|
@Before
|
||||||
fun setUp() {
|
fun setUp() {
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
// ACTION_CLASS: org.jetbrains.kotlin.idea.actions.generate.KotlinGenerateTestSupportActionBase$SetUp
|
// ACTION_CLASS: org.jetbrains.kotlin.idea.actions.generate.KotlinGenerateTestSupportActionBase$SetUp
|
||||||
// CONFIGURE_LIBRARY: JUnit@lib/junit-4.12.jar
|
// CONFIGURE_LIBRARY: JUnit@lib/junit-4.12.jar
|
||||||
|
// TEST_FRAMEWORK: JUnit4
|
||||||
import org.junit.Before
|
import org.junit.Before
|
||||||
|
|
||||||
class A {<caret>
|
class A {<caret>
|
||||||
|
|||||||
+1
-5
@@ -1,13 +1,9 @@
|
|||||||
// ACTION_CLASS: org.jetbrains.kotlin.idea.actions.generate.KotlinGenerateTestSupportActionBase$SetUp
|
// ACTION_CLASS: org.jetbrains.kotlin.idea.actions.generate.KotlinGenerateTestSupportActionBase$SetUp
|
||||||
// CONFIGURE_LIBRARY: JUnit@lib/junit-4.12.jar
|
// CONFIGURE_LIBRARY: JUnit@lib/junit-4.12.jar
|
||||||
|
// TEST_FRAMEWORK: JUnit4
|
||||||
import org.junit.Before
|
import org.junit.Before
|
||||||
|
|
||||||
class A {
|
class A {
|
||||||
@org.testng.annotations.BeforeMethod
|
|
||||||
fun setUp() {
|
|
||||||
TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
|
|
||||||
}
|
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
fun setUp() {
|
fun setUp() {
|
||||||
throw UnsupportedOperationException()
|
throw UnsupportedOperationException()
|
||||||
|
|||||||
+1
@@ -1,5 +1,6 @@
|
|||||||
// ACTION_CLASS: org.jetbrains.kotlin.idea.actions.generate.KotlinGenerateTestSupportActionBase$SetUp
|
// ACTION_CLASS: org.jetbrains.kotlin.idea.actions.generate.KotlinGenerateTestSupportActionBase$SetUp
|
||||||
// CONFIGURE_LIBRARY: JUnit@lib/junit-4.12.jar
|
// CONFIGURE_LIBRARY: JUnit@lib/junit-4.12.jar
|
||||||
|
// TEST_FRAMEWORK: JUnit4
|
||||||
open class A {
|
open class A {
|
||||||
open fun setUp() {
|
open fun setUp() {
|
||||||
|
|
||||||
|
|||||||
+1
@@ -2,6 +2,7 @@ import org.junit.Before
|
|||||||
|
|
||||||
// ACTION_CLASS: org.jetbrains.kotlin.idea.actions.generate.KotlinGenerateTestSupportActionBase$SetUp
|
// ACTION_CLASS: org.jetbrains.kotlin.idea.actions.generate.KotlinGenerateTestSupportActionBase$SetUp
|
||||||
// CONFIGURE_LIBRARY: JUnit@lib/junit-4.12.jar
|
// CONFIGURE_LIBRARY: JUnit@lib/junit-4.12.jar
|
||||||
|
// TEST_FRAMEWORK: JUnit4
|
||||||
open class A {
|
open class A {
|
||||||
open fun setUp() {
|
open fun setUp() {
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
// ACTION_CLASS: org.jetbrains.kotlin.idea.actions.generate.KotlinGenerateTestSupportActionBase$TearDown
|
// ACTION_CLASS: org.jetbrains.kotlin.idea.actions.generate.KotlinGenerateTestSupportActionBase$TearDown
|
||||||
// CONFIGURE_LIBRARY: JUnit@lib/junit-4.12.jar
|
// CONFIGURE_LIBRARY: JUnit@lib/junit-4.12.jar
|
||||||
|
// TEST_FRAMEWORK: JUnit4
|
||||||
class A {<caret>
|
class A {<caret>
|
||||||
|
|
||||||
}
|
}
|
||||||
+1
@@ -2,6 +2,7 @@ import org.junit.After
|
|||||||
|
|
||||||
// ACTION_CLASS: org.jetbrains.kotlin.idea.actions.generate.KotlinGenerateTestSupportActionBase$TearDown
|
// ACTION_CLASS: org.jetbrains.kotlin.idea.actions.generate.KotlinGenerateTestSupportActionBase$TearDown
|
||||||
// CONFIGURE_LIBRARY: JUnit@lib/junit-4.12.jar
|
// CONFIGURE_LIBRARY: JUnit@lib/junit-4.12.jar
|
||||||
|
// TEST_FRAMEWORK: JUnit4
|
||||||
class A {
|
class A {
|
||||||
@After
|
@After
|
||||||
fun tearDown() {
|
fun tearDown() {
|
||||||
|
|||||||
+1
@@ -1,5 +1,6 @@
|
|||||||
// ACTION_CLASS: org.jetbrains.kotlin.idea.actions.generate.KotlinGenerateTestSupportActionBase$TearDown
|
// ACTION_CLASS: org.jetbrains.kotlin.idea.actions.generate.KotlinGenerateTestSupportActionBase$TearDown
|
||||||
// CONFIGURE_LIBRARY: JUnit@lib/junit-4.12.jar
|
// CONFIGURE_LIBRARY: JUnit@lib/junit-4.12.jar
|
||||||
|
// TEST_FRAMEWORK: JUnit4
|
||||||
import org.junit.After
|
import org.junit.After
|
||||||
|
|
||||||
class A {<caret>
|
class A {<caret>
|
||||||
|
|||||||
+1
-5
@@ -1,13 +1,9 @@
|
|||||||
// ACTION_CLASS: org.jetbrains.kotlin.idea.actions.generate.KotlinGenerateTestSupportActionBase$TearDown
|
// ACTION_CLASS: org.jetbrains.kotlin.idea.actions.generate.KotlinGenerateTestSupportActionBase$TearDown
|
||||||
// CONFIGURE_LIBRARY: JUnit@lib/junit-4.12.jar
|
// CONFIGURE_LIBRARY: JUnit@lib/junit-4.12.jar
|
||||||
|
// TEST_FRAMEWORK: JUnit4
|
||||||
import org.junit.After
|
import org.junit.After
|
||||||
|
|
||||||
class A {
|
class A {
|
||||||
@org.testng.annotations.AfterMethod
|
|
||||||
fun tearDown() {
|
|
||||||
TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
|
|
||||||
}
|
|
||||||
|
|
||||||
@After
|
@After
|
||||||
fun tearDown() {
|
fun tearDown() {
|
||||||
throw UnsupportedOperationException()
|
throw UnsupportedOperationException()
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
// ACTION_CLASS: org.jetbrains.kotlin.idea.actions.generate.KotlinGenerateTestSupportActionBase$Test
|
// ACTION_CLASS: org.jetbrains.kotlin.idea.actions.generate.KotlinGenerateTestSupportActionBase$Test
|
||||||
// CONFIGURE_LIBRARY: JUnit@lib/junit-4.12.jar
|
// CONFIGURE_LIBRARY: JUnit@lib/junit-4.12.jar
|
||||||
|
// TEST_FRAMEWORK: JUnit4
|
||||||
class A {<caret>
|
class A {<caret>
|
||||||
|
|
||||||
}
|
}
|
||||||
+1
@@ -2,6 +2,7 @@ import org.junit.Test
|
|||||||
|
|
||||||
// ACTION_CLASS: org.jetbrains.kotlin.idea.actions.generate.KotlinGenerateTestSupportActionBase$Test
|
// ACTION_CLASS: org.jetbrains.kotlin.idea.actions.generate.KotlinGenerateTestSupportActionBase$Test
|
||||||
// CONFIGURE_LIBRARY: JUnit@lib/junit-4.12.jar
|
// CONFIGURE_LIBRARY: JUnit@lib/junit-4.12.jar
|
||||||
|
// TEST_FRAMEWORK: JUnit4
|
||||||
class A {
|
class A {
|
||||||
@Test
|
@Test
|
||||||
fun name() {
|
fun name() {
|
||||||
|
|||||||
+7
@@ -17,7 +17,9 @@
|
|||||||
package org.jetbrains.kotlin.idea.codeInsight.generate
|
package org.jetbrains.kotlin.idea.codeInsight.generate
|
||||||
|
|
||||||
import com.intellij.openapi.roots.ModuleRootManager
|
import com.intellij.openapi.roots.ModuleRootManager
|
||||||
|
import org.jetbrains.kotlin.idea.actions.generate.KotlinGenerateTestSupportActionBase
|
||||||
import org.jetbrains.kotlin.idea.util.application.runWriteAction
|
import org.jetbrains.kotlin.idea.util.application.runWriteAction
|
||||||
|
import org.jetbrains.kotlin.test.InTextDirectivesUtils
|
||||||
|
|
||||||
abstract class AbstractGenerateTestSupportMethodActionTest : AbstractCodeInsightActionTest() {
|
abstract class AbstractGenerateTestSupportMethodActionTest : AbstractCodeInsightActionTest() {
|
||||||
private fun setUpTestSourceRoot() {
|
private fun setUpTestSourceRoot() {
|
||||||
@@ -33,6 +35,11 @@ abstract class AbstractGenerateTestSupportMethodActionTest : AbstractCodeInsight
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun createAction(fileText: String) =
|
||||||
|
(super.createAction(fileText) as KotlinGenerateTestSupportActionBase).apply {
|
||||||
|
testFrameworkToUse = InTextDirectivesUtils.findStringWithPrefixes(fileText, "// TEST_FRAMEWORK:")
|
||||||
|
}
|
||||||
|
|
||||||
override fun doTest(path: String) {
|
override fun doTest(path: String) {
|
||||||
setUpTestSourceRoot()
|
setUpTestSourceRoot()
|
||||||
super.doTest(path)
|
super.doTest(path)
|
||||||
|
|||||||
Reference in New Issue
Block a user