Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import org.jetbrains.intellij.platform.gradle.IntelliJPlatformType
import org.jetbrains.intellij.platform.gradle.TestFrameworkType

fun properties(key: String) = project.findProperty(key).toString()

Expand Down Expand Up @@ -65,9 +66,10 @@ dependencies {
implementation("org.jetbrains.kotlin:kotlin-stdlib:2.1.0")
implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.6.0")
testImplementation("io.mockk:mockk:1.13.12")
testImplementation("org.jetbrains.kotlin:kotlin-test-junit5")
testImplementation("junit:junit:4.13.2")

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

This change replaces the kotlin-test-junit5 dependency with junit:4.13.2, standardizing on JUnit 4. While this resolves dependency issues, it would be beneficial to consider migrating to JUnit 5. JUnit 5 is the current standard for JVM testing and offers numerous improvements, such as a more flexible extension model and better support for Kotlin. Since you are in the process of rewriting tests, it might be a good opportunity to adopt this more modern framework.

intellijPlatform {
clion(runIdeVersion)
testFramework(TestFrameworkType.Platform)
}
}

Expand Down
44 changes: 0 additions & 44 deletions src/test/kotlin/io/xmake/TestData.kt

This file was deleted.

42 changes: 42 additions & 0 deletions src/test/kotlin/io/xmake/project/toolkit/ToolkitManagerTest.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package io.xmake.project.toolkit

import junit.framework.TestCase.assertEquals
import junit.framework.TestCase.assertNotNull
Comment on lines +3 to +4

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

These imports are from the older JUnit 3 TestCase class. For JUnit 4 tests, it's more conventional to use static imports from org.junit.Assert. This is the standard practice for JUnit 4.

For even more idiomatic Kotlin, you could use the kotlin.test library, which provides assertion functions that are well-integrated with the language.

Suggested change
import junit.framework.TestCase.assertEquals
import junit.framework.TestCase.assertNotNull
import org.junit.Assert.assertEquals
import org.junit.Assert.assertNotNull

import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
import org.junit.runners.JUnit4

@RunWith(JUnit4::class)
class ToolkitManagerTest {

private lateinit var toolkitManager: ToolkitManager

@Before
fun setUp() {
toolkitManager = ToolkitManager(CoroutineScope(Dispatchers.Default))

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

Using Dispatchers.Default in unit tests is a source of potential flakiness and non-determinism, as it executes code on a shared pool of background threads. For testing coroutines, it is strongly recommended to use the kotlinx-coroutines-test library. It provides test dispatchers and the runTest builder to give you full control over coroutine execution, leading to faster and more reliable tests.

toolkitManager.loadState(ToolkitManager.State())
}

@Test
fun `test register and find toolkit`() {
val localToolkit = Toolkit(
name = "Local xmake",
host = ToolkitHost(ToolkitHostType.LOCAL),
path = "/usr/local/bin/xmake",
version = "3.0.2"
)

toolkitManager.registerToolkit(localToolkit)

val registeredToolkits = toolkitManager.getRegisteredToolkits()
assertEquals("Should have one registered toolkit", 1, registeredToolkits.size)
assertEquals("The registered toolkit should be the one we added", localToolkit, registeredToolkits.first())

val foundToolkit = toolkitManager.findRegisteredToolkitById(localToolkit.id)
assertNotNull("Should find the toolkit by its ID", foundToolkit)
assertEquals("The found toolkit should be the same as the original", localToolkit, foundToolkit)
}
}
102 changes: 0 additions & 102 deletions src/test/kotlin/io/xmake/utils/interact/InteractTest.kt

This file was deleted.