Skip to content

Commit fcc8782

Browse files
FantoomForNeVeR
authored andcommitted
(#291) Tests: Migrate debugger tests to JUnit 5
1 parent 8023855 commit fcc8782

File tree

9 files changed

+209
-123
lines changed

9 files changed

+209
-123
lines changed

src/test/kotlin/com/intellij/plugin/powershell/debugger/BreakpointTest.kt

Lines changed: 31 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,18 @@ import com.intellij.openapi.fileEditor.ex.FileEditorManagerEx
44
import com.intellij.plugin.powershell.ide.debugger.PowerShellSuspendContext
55
import com.intellij.plugin.powershell.testFramework.DebuggerTestBase
66
import com.intellij.plugin.powershell.testFramework.PowerShellTestSession
7-
import com.intellij.testFramework.HeavyPlatformTestCase.assertTrue
7+
import com.intellij.plugin.powershell.testFramework.runInEdt
8+
import com.intellij.testFramework.junit5.TestApplication
89
import com.intellij.xdebugger.XDebuggerTestUtil
910
import com.intellij.xdebugger.XTestCompositeNode
1011
import com.jetbrains.rd.util.lifetime.Lifetime
11-
import junit.framework.TestCase
12+
import org.junit.jupiter.api.Assertions
13+
import org.junit.jupiter.api.Test
1214

15+
@TestApplication
1316
class BreakpointTest : DebuggerTestBase() {
1417

18+
@Test
1519
fun testBreakpoint() {
1620
runInEdt {
1721
val psiFile = copyAndOpenFile("debugger/testBreakpoint.ps1")
@@ -23,16 +27,19 @@ class BreakpointTest : DebuggerTestBase() {
2327
XDebuggerTestUtil.toggleBreakpoint(project, file, line)
2428
Lifetime.using { lt ->
2529
val debugSession = testSession.startDebugSession(lt)
26-
assertTrue("Pause should be triggered in ${testSession.waitForBackgroundTimeout}", XDebuggerTestUtil.waitFor(
27-
testSession.sessionListener.pausedSemaphore,
28-
testSession.waitForBackgroundTimeout.toMillis()
29-
))
30+
Assertions.assertTrue(
31+
XDebuggerTestUtil.waitFor(
32+
testSession.sessionListener.pausedSemaphore,
33+
testSession.waitForBackgroundTimeout.toMillis()
34+
), "Pause should be triggered in ${testSession.waitForBackgroundTimeout}"
35+
)
3036
val suspendContext = debugSession.suspendContext as PowerShellSuspendContext
31-
TestCase.assertEquals(line, suspendContext.activeExecutionStack.topFrame?.sourcePosition?.line)
37+
Assertions.assertEquals(line, suspendContext.activeExecutionStack.topFrame?.sourcePosition?.line)
3238
}
3339
}
3440
}
3541

42+
@Test
3643
fun testBreakpointTwoFiles() {
3744
runInEdt {
3845
val psiFile = copyAndOpenFile("debugger/testBreakpointTwoFiles.ps1")
@@ -47,20 +54,23 @@ class BreakpointTest : DebuggerTestBase() {
4754

4855
Lifetime.using { lt ->
4956
val debugSession = testSession.startDebugSession(lt)
50-
assertTrue("Pause should be triggered in ${testSession.waitForBackgroundTimeout}", XDebuggerTestUtil.waitFor(
51-
testSession.sessionListener.pausedSemaphore,
52-
testSession.waitForBackgroundTimeout.toMillis()
53-
))
57+
Assertions.assertTrue(
58+
XDebuggerTestUtil.waitFor(
59+
testSession.sessionListener.pausedSemaphore,
60+
testSession.waitForBackgroundTimeout.toMillis()
61+
), "Pause should be triggered in ${testSession.waitForBackgroundTimeout}"
62+
)
5463
val suspendContext = debugSession.suspendContext as PowerShellSuspendContext
55-
TestCase.assertEquals(
64+
Assertions.assertEquals(
5665
psiSecondFile.virtualFile.toNioPath(),
5766
suspendContext.activeExecutionStack.topFrame?.sourcePosition?.file?.toNioPath()
5867
)
59-
TestCase.assertEquals(line, suspendContext.activeExecutionStack.topFrame?.sourcePosition?.line)
68+
Assertions.assertEquals(line, suspendContext.activeExecutionStack.topFrame?.sourcePosition?.line)
6069
}
6170
}
6271
}
6372

73+
@Test
6474
fun testConditionalBreakpoint()
6575
{
6676
runInEdt {
@@ -78,21 +88,23 @@ class BreakpointTest : DebuggerTestBase() {
7888
XDebuggerTestUtil.setBreakpointCondition(project, line, condition)
7989
Lifetime.using { lt ->
8090
val debugSession = testSession.startDebugSession(lt)
81-
assertTrue("Pause should be triggered in ${testSession.waitForBackgroundTimeout}", XDebuggerTestUtil.waitFor(
82-
testSession.sessionListener.pausedSemaphore,
83-
testSession.waitForBackgroundTimeout.toMillis()
84-
))
91+
Assertions.assertTrue(
92+
XDebuggerTestUtil.waitFor(
93+
testSession.sessionListener.pausedSemaphore,
94+
testSession.waitForBackgroundTimeout.toMillis()
95+
), "Pause should be triggered in ${testSession.waitForBackgroundTimeout}"
96+
)
8597
val suspendContext = debugSession.suspendContext as PowerShellSuspendContext
8698
val topFrame = suspendContext.activeExecutionStack.topFrame!!
8799
val children = XTestCompositeNode(topFrame).collectChildren()
88100
val variableValue = XDebuggerTestUtil.findVar(children, variableName)
89101
val variableValueNode = XDebuggerTestUtil.computePresentation(variableValue)
90-
TestCase.assertEquals(value.toString(), variableValueNode.myValue)
102+
Assertions.assertEquals(value.toString(), variableValueNode.myValue)
91103
}
92104
}
93105
}
94106

95-
override fun tearDownEdt() {
107+
override fun tearDownInEdt() {
96108
FileEditorManagerEx.getInstanceEx(project).closeAllFiles()
97109
}
98110
}

src/test/kotlin/com/intellij/plugin/powershell/debugger/EvaluationTest.kt

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,17 @@ package com.intellij.plugin.powershell.debugger
33
import com.intellij.openapi.fileEditor.ex.FileEditorManagerEx
44
import com.intellij.plugin.powershell.testFramework.DebuggerTestBase
55
import com.intellij.plugin.powershell.testFramework.PowerShellTestSession
6+
import com.intellij.plugin.powershell.testFramework.runInEdt
7+
import com.intellij.testFramework.junit5.TestApplication
68
import com.intellij.xdebugger.XDebuggerTestUtil
79
import com.jetbrains.rd.util.lifetime.Lifetime
8-
import junit.framework.TestCase
10+
import org.junit.jupiter.api.Assertions
11+
import org.junit.jupiter.api.Test
912

13+
@TestApplication
1014
class EvaluationTest: DebuggerTestBase() {
1115

16+
@Test
1217
fun testEvaluation() {
1318
runInEdt {
1419
val psiFile = copyAndOpenFile("debugger/testBreakpoint.ps1")
@@ -23,19 +28,19 @@ class EvaluationTest: DebuggerTestBase() {
2328
XDebuggerTestUtil.toggleBreakpoint(project, file, line)
2429
Lifetime.using { lt ->
2530
val debugSession = testSession.startDebugSession(lt)
26-
assertTrue("Pause should be triggered in ${testSession.waitForBackgroundTimeout}", XDebuggerTestUtil.waitFor(
31+
Assertions.assertTrue(XDebuggerTestUtil.waitFor(
2732
testSession.sessionListener.pausedSemaphore,
2833
testSession.waitForBackgroundTimeout.toMillis()
29-
))
34+
), "Pause should be triggered in ${testSession.waitForBackgroundTimeout}")
3035
val variableValue =
3136
XDebuggerTestUtil.evaluate(debugSession, expression, testSession.waitForBackgroundTimeout.toMillis()).first
3237
val variableValueNode = XDebuggerTestUtil.computePresentation(variableValue)
33-
TestCase.assertEquals(expectedResult, variableValueNode.myValue)
38+
Assertions.assertEquals(expectedResult, variableValueNode.myValue)
3439
}
3540
}
3641
}
3742

38-
override fun tearDownEdt() {
43+
override fun tearDownInEdt() {
3944
FileEditorManagerEx.getInstanceEx(project).closeAllFiles()
4045
}
4146
}

src/test/kotlin/com/intellij/plugin/powershell/debugger/StepTest.kt

Lines changed: 56 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,17 @@ import com.intellij.openapi.fileEditor.ex.FileEditorManagerEx
44
import com.intellij.plugin.powershell.ide.debugger.PowerShellSuspendContext
55
import com.intellij.plugin.powershell.testFramework.DebuggerTestBase
66
import com.intellij.plugin.powershell.testFramework.PowerShellTestSession
7+
import com.intellij.plugin.powershell.testFramework.runInEdt
8+
import com.intellij.testFramework.junit5.TestApplication
79
import com.intellij.xdebugger.XDebuggerTestUtil
810
import com.jetbrains.rd.util.lifetime.Lifetime
9-
import junit.framework.TestCase
11+
import org.junit.jupiter.api.Assertions
12+
import org.junit.jupiter.api.Test
1013

11-
class StepTest: DebuggerTestBase() {
14+
@TestApplication
15+
class StepTest : DebuggerTestBase() {
1216

17+
@Test
1318
fun testStepOver() {
1419
runInEdt {
1520
val psiFile = copyAndOpenFile("debugger/stepTest.ps1")
@@ -22,25 +27,31 @@ class StepTest: DebuggerTestBase() {
2227
XDebuggerTestUtil.toggleBreakpoint(project, file, line)
2328
Lifetime.using { lt ->
2429
val debugSession = testSession.startDebugSession(lt)
25-
assertTrue("Pause should be triggered in ${testSession.waitForBackgroundTimeout}", XDebuggerTestUtil.waitFor(
26-
testSession.sessionListener.pausedSemaphore,
27-
testSession.waitForBackgroundTimeout.toMillis()
28-
))
30+
31+
Assertions.assertTrue(
32+
XDebuggerTestUtil.waitFor(
33+
testSession.sessionListener.pausedSemaphore, testSession.waitForBackgroundTimeout.toMillis()
34+
), "Pause should be triggered in ${testSession.waitForBackgroundTimeout}"
35+
)
36+
2937
val suspendContext = debugSession.suspendContext as PowerShellSuspendContext
30-
TestCase.assertEquals(line, suspendContext.activeExecutionStack.topFrame?.sourcePosition?.line)
38+
Assertions.assertEquals(line, suspendContext.activeExecutionStack.topFrame?.sourcePosition?.line)
3139
debugSession.stepOver(false)
32-
assertTrue("Pause should be triggered in ${testSession.waitForBackgroundTimeout}", XDebuggerTestUtil.waitFor(
33-
testSession.sessionListener.pausedSemaphore,
34-
testSession.waitForBackgroundTimeout.toMillis()
35-
))
36-
TestCase.assertEquals(
40+
41+
Assertions.assertTrue(
42+
XDebuggerTestUtil.waitFor(
43+
testSession.sessionListener.pausedSemaphore, testSession.waitForBackgroundTimeout.toMillis()
44+
), "Pause should be triggered in ${testSession.waitForBackgroundTimeout}"
45+
)
46+
Assertions.assertEquals(
3747
line + 1,
3848
(debugSession.suspendContext as PowerShellSuspendContext).activeExecutionStack.topFrame?.sourcePosition?.line
3949
)
4050
}
4151
}
4252
}
4353

54+
@Test
4455
fun testStepIn() {
4556
runInEdt {
4657
val psiFile = copyAndOpenFile("debugger/stepTest.ps1")
@@ -55,25 +66,34 @@ class StepTest: DebuggerTestBase() {
5566
XDebuggerTestUtil.toggleBreakpoint(project, file, line)
5667
Lifetime.using { lt ->
5768
val debugSession = testSession.startDebugSession(lt)
58-
assertTrue("Pause should be triggered in ${testSession.waitForBackgroundTimeout}", XDebuggerTestUtil.waitFor(
59-
testSession.sessionListener.pausedSemaphore,
60-
testSession.waitForBackgroundTimeout.toMillis()
61-
))
62-
val suspendContext = debugSession.suspendContext as PowerShellSuspendContext
63-
TestCase.assertEquals(line, suspendContext.activeExecutionStack.topFrame?.sourcePosition?.line)
69+
70+
Assertions.assertTrue(
71+
XDebuggerTestUtil.waitFor(
72+
testSession.sessionListener.pausedSemaphore, testSession.waitForBackgroundTimeout.toMillis()
73+
), "Pause should be triggered in ${testSession.waitForBackgroundTimeout}"
74+
)
75+
76+
Assertions.assertEquals(
77+
line,
78+
(debugSession.suspendContext as PowerShellSuspendContext).activeExecutionStack.topFrame?.sourcePosition?.line
79+
)
80+
6481
debugSession.stepInto()
65-
assertTrue("Pause should be triggered in ${testSession.waitForBackgroundTimeout}", XDebuggerTestUtil.waitFor(
66-
testSession.sessionListener.pausedSemaphore,
67-
testSession.waitForBackgroundTimeout.toMillis()
68-
))
69-
TestCase.assertEquals(
82+
83+
Assertions.assertTrue(
84+
XDebuggerTestUtil.waitFor(
85+
testSession.sessionListener.pausedSemaphore, testSession.waitForBackgroundTimeout.toMillis()
86+
), "Pause should be triggered in ${testSession.waitForBackgroundTimeout}"
87+
)
88+
Assertions.assertEquals(
7089
stepInLine,
7190
(debugSession.suspendContext as PowerShellSuspendContext).activeExecutionStack.topFrame?.sourcePosition?.line
7291
)
7392
}
7493
}
7594
}
7695

96+
@Test
7797
fun testStepOut() {
7898
runInEdt {
7999
val psiFile = copyAndOpenFile("debugger/stepTest.ps1")
@@ -89,26 +109,28 @@ class StepTest: DebuggerTestBase() {
89109
XDebuggerTestUtil.toggleBreakpoint(project, file, line)
90110
Lifetime.using { lt ->
91111
val debugSession = testSession.startDebugSession(lt)
92-
assertTrue("Pause should be triggered in ${testSession.waitForBackgroundTimeout}", XDebuggerTestUtil.waitFor(
93-
testSession.sessionListener.pausedSemaphore,
94-
testSession.waitForBackgroundTimeout.toMillis()
95-
))
112+
Assertions.assertTrue(
113+
XDebuggerTestUtil.waitFor(
114+
testSession.sessionListener.pausedSemaphore, testSession.waitForBackgroundTimeout.toMillis()
115+
), "Pause should be triggered in ${testSession.waitForBackgroundTimeout}"
116+
)
96117
val suspendContext = debugSession.suspendContext as PowerShellSuspendContext
97-
TestCase.assertEquals(line, suspendContext.activeExecutionStack.topFrame?.sourcePosition?.line)
118+
Assertions.assertEquals(line, suspendContext.activeExecutionStack.topFrame?.sourcePosition?.line)
98119
debugSession.stepOut()
99-
assertTrue("Pause should be triggered in ${testSession.waitForBackgroundTimeout}", XDebuggerTestUtil.waitFor(
100-
testSession.sessionListener.pausedSemaphore,
101-
testSession.waitForBackgroundTimeout.toMillis()
102-
))
103-
TestCase.assertEquals(
120+
Assertions.assertTrue(
121+
XDebuggerTestUtil.waitFor(
122+
testSession.sessionListener.pausedSemaphore, testSession.waitForBackgroundTimeout.toMillis()
123+
), "Pause should be triggered in ${testSession.waitForBackgroundTimeout}"
124+
)
125+
Assertions.assertEquals(
104126
stepOutLine,
105127
(debugSession.suspendContext as PowerShellSuspendContext).activeExecutionStack.topFrame?.sourcePosition?.line
106128
)
107129
}
108130
}
109131
}
110132

111-
override fun tearDownEdt() {
133+
override fun tearDownInEdt() {
112134
FileEditorManagerEx.getInstanceEx(project).closeAllFiles()
113135
}
114136
}

0 commit comments

Comments
 (0)