Skip to content

Commit

Permalink
Add unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Petr Komissarov committed May 16, 2024
1 parent 9697c5e commit fdafaf9
Show file tree
Hide file tree
Showing 9 changed files with 199 additions and 22 deletions.
38 changes: 37 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ on:
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true

jobs:

# Prepare environment and build the plugin
Expand Down Expand Up @@ -76,6 +76,42 @@ jobs:
name: ${{ steps.artifact.outputs.filename }}
path: ./build/distributions/content/*/*

# Run tests and upload a code coverage report
test:
name: Test
needs: [ build ]
runs-on: ubuntu-latest
steps:

# Check out current repository
- name: Fetch Sources
uses: actions/checkout@v4

# Set up Java environment for the next steps
- name: Setup Java
uses: actions/setup-java@v4
with:
distribution: zulu
java-version: 17

# Setup Gradle
- name: Setup Gradle
uses: gradle/actions/setup-gradle@v3
with:
gradle-home-cache-cleanup: true

# Run tests
- name: Run Tests
run: ./gradlew check -DtestCi=true

# Collect Tests Result of failed tests
- name: Collect Tests Result
if: ${{ failure() }}
uses: actions/upload-artifact@v4
with:
name: tests-result
path: ${{ github.workspace }}/build/reports/tests

# Run plugin structure verification along with IntelliJ Plugin Verifier
verify:
name: Verify plugin
Expand Down
10 changes: 9 additions & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ kotlin {
}

tasks {
wrapper {
gradleVersion = properties("gradleVersion").get()
}

buildSearchableOptions {
enabled = false
}
Expand Down Expand Up @@ -94,8 +98,12 @@ tasks {
"java.util.logging.manager",
"java.util.logging.LogManager"
)
systemProperty(
"TEST_CI",
System.getProperty("testCi")
)
reports {
html.required.set(false)
html.required.set(true)
junitXml.required.set(false)
}
testLogging {
Expand Down
41 changes: 21 additions & 20 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
pluginVersion = 1.0.5
pluginGroup = ru.testit.management
pluginName = testit_management
pluginRepositoryUrl = https://github.com/testit-tms/testit-management/
pluginSinceBuild = 231
pluginUntilBuild = 241.*
platformType = IC
platformVersion = 2024.1.1
platformPlugins =
javaEncoding = UTF-8
javaVersion = 17
kotlin.code.style = official
kotlin.stdlib.default.dependency = false
org.gradle.caching = true
org.gradle.configuration-cache = true
org.gradle.configureondemand = true
org.gradle.parallel = true
org.gradle.warning.mode = all
org.gradle.welcome = never
org.gradle.jvmargs = -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 -XX:+UseParallelGC
pluginVersion=1.0.5
pluginGroup=ru.testit.management
pluginName=testit_management
pluginRepositoryUrl=https://github.com/testit-tms/testit-management/
gradleVersion=8.7
pluginSinceBuild=231
pluginUntilBuild=241.*
platformType=IC
platformVersion=2024.1.1
platformPlugins=
javaEncoding=UTF-8
javaVersion=17
kotlin.code.style=official
kotlin.stdlib.default.dependency=false
org.gradle.caching=true
org.gradle.configuration-cache=true
org.gradle.configureondemand=true
org.gradle.parallel=true
org.gradle.warning.mode=all
org.gradle.welcome=never
org.gradle.jvmargs=-XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 -XX:+UseParallelGC
Empty file.
25 changes: 25 additions & 0 deletions src/test/kotlin/ru/testit/management/ClientTests.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package ru.testit.management

import org.junit.jupiter.api.DisplayName
import ru.testit.management.clients.TmsClient
import kotlin.test.DefaultAsserter.assertEquals
import kotlin.test.Test


@DisplayName("Client")
class ClientTests {

@DisplayName("Validation")
@Test
fun checkMessage() {
// Arrange
val expected =
"<html><body style='width: 350px;'>Expected URL scheme 'http' or 'https' but no scheme was found for /api/v...</body></html>"

// Act
val actual = TmsClient.getSettingsValidationErrorMsg("", "", "")

// Assert
assertEquals("Validation error message assertion failed!", expected, actual)
}
}
29 changes: 29 additions & 0 deletions src/test/kotlin/ru/testit/management/ClipboardTests.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package ru.testit.management

import org.junit.jupiter.api.DisplayName
import org.junit.jupiter.api.condition.DisabledIfSystemProperty
import ru.testit.management.utils.ClipboardUtils
import java.awt.Toolkit.getDefaultToolkit
import java.awt.datatransfer.DataFlavor
import kotlin.test.DefaultAsserter.assertEquals
import kotlin.test.Test


@DisplayName("Clipboard")
class ClipboardTests {

@DisplayName("Copy")
@DisabledIfSystemProperty(named = "TEST_CI", matches = "true")
@Test
fun checkCopy() {
// Arrange
val expected = "Test123"

// Act
ClipboardUtils.copyToClipboard(expected)
val actual = getDefaultToolkit().systemClipboard.getData(DataFlavor.stringFlavor) as String

// Assert
assertEquals("Clipboard value assertion failed!", expected, actual)
}
}
53 changes: 53 additions & 0 deletions src/test/kotlin/ru/testit/management/CodeSnippedTests.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package ru.testit.management

import kotlinx.collections.immutable.persistentSetOf
import org.junit.jupiter.api.DisplayName
import ru.testit.client.model.StepModel
import ru.testit.management.utils.CodeSnippedUtils
import ru.testit.management.windows.tools.TmsNodeModel
import kotlin.test.DefaultAsserter.assertEquals
import kotlin.test.Test


@DisplayName("Code snippet")
class CodeSnippedTests {

@DisplayName("Create")
@Test
fun checkCodeSnippet() {
// Arrange
val name = "Test name"
val globalID = 12345L

val preModel = StepModel()
preModel.action = "Precondition text"
val pre = persistentSetOf(preModel)

val stepModel = StepModel()
stepModel.action = "Step text"
val steps = persistentSetOf(stepModel)

val postModel = StepModel()
postModel.action = "Postcondition text"
val post = persistentSetOf(postModel)

val model = TmsNodeModel(name, globalID, pre, steps, post)
val expected = """@WorkItemIds("$globalID")
@Test
public void testName() {
// See work item [$globalID] for detailed steps description
// Pre:
// ${preModel.action}
// Steps:
// ${stepModel.action}
// Post:
// ${postModel.action}
}"""

// Act
val actual = CodeSnippedUtils.getNewSnippet(model)

// Assert
assertEquals("Code snipped text assertion failed!", expected, actual)
}
}
24 changes: 24 additions & 0 deletions src/test/kotlin/ru/testit/management/MessagesTests.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package ru.testit.management

import org.junit.jupiter.api.DisplayName
import ru.testit.management.utils.MessagesUtils
import kotlin.test.DefaultAsserter.assertEquals
import kotlin.test.Test


@DisplayName("Messages")
class MessagesTests {

@DisplayName("Copy")
@Test
fun checkCopy() {
// Arrange
val expected = "Copy"

// Act
val actual = MessagesUtils.get("window.tool.popup.copy.text")

// Assert
assertEquals("Message text assertion failed!", expected, actual)
}
}
1 change: 1 addition & 0 deletions src/test/resources/junit-platform.properties
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
junit.jupiter.execution.parallel.enabled=true
junit.jupiter.execution.parallel.mode.default=same_thread
junit.jupiter.execution.parallel.mode.classes.default=concurrent
junit.jupiter.displayname.generator.default=org.junit.jupiter.api.DisplayNameGenerator$ReplaceUnderscores

0 comments on commit fdafaf9

Please sign in to comment.