Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
497996c
build: update gradle config to support testing with JUnit
Apr 17, 2025
9f8ae07
build: update gradle config to support testing with JUnit
Apr 17, 2025
415f854
build: update gradle config to support testing with JUnit, create Lob…
Apr 17, 2025
ae285cc
build: update LobbyTest.kt
Apr 17, 2025
b06b04b
build: create GameSettingsTest.kt
Apr 17, 2025
ba76ada
build: create GameSettingsTest.kt
Apr 17, 2025
0c4a512
build: create BoardSquareFactoryTest.kt
Apr 17, 2025
56cedfe
build: create PieceFactoryTest.kt
Apr 17, 2025
798e640
build: ktlint
Apr 17, 2025
6b317a7
build: Add basic UI test
Apr 18, 2025
47f5a20
Merge remote-tracking branch 'origin/main' into build/63-build-create…
Apr 18, 2025
adc374a
build: update tests
Apr 18, 2025
1e04df7
build: Add tests for PresenterManager
Apr 18, 2025
61d3591
build: Create GameTest, update LobbyTest
Apr 18, 2025
17d7cb8
build: ktlinting autofix
Apr 18, 2025
2324496
build: ktlinting
Apr 18, 2025
313b884
Merge remote-tracking branch 'origin/main' into build/63-build-create…
Apr 18, 2025
7c3fc93
build: Add jacoco package
Apr 19, 2025
4652323
build: Update README.md
Apr 19, 2025
46fc4ae
Merge branch 'main' into build/63-build-create-basic-tests
WilliamTjonndal Apr 19, 2025
a3e7224
build: Create MockView.kt
Apr 20, 2025
64a29e7
build: Update PresenterManagerTest tests
Apr 20, 2025
4c064cd
build: Update model tests
Apr 20, 2025
5ae3b09
Merge remote-tracking branch 'origin/main' into build/63-build-create…
Apr 20, 2025
b09f741
build: ktlint
Apr 20, 2025
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
13 changes: 11 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,6 @@ For VSCode or Neovim users, you know what you are doing.

### Debug and Testing

This is not setup yet! Remove this when setup is complete and add GitHub action.

Run unit tests:

```bash
Expand All @@ -137,6 +135,17 @@ Run unit tests with coverage:
./gradlew test jacocoTestReport
```

The test coverage reports for each subproject can be found at:
- [Chessevolved model](chessevolved_model/build/reports/jacoco/test/html/index.html)
- [Chessevolved presenter](chessevolved_presenter/build/reports/jacoco/test/html/index.html)
- [Lwjgl3 (Desktop launcher)](lwjgl3/build/reports/jacoco/test/html/index.html)

If Jacoco does not generate coverage reports when running the previous command, run the following:

```bash
./gradlew test --rerun jacocoTestReport
```

### Dependencies

- [KTX](https://libktx.github.io/) - Kotlin extensions for LibGDX
Expand Down
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ plugins {
allprojects {
apply plugin: 'eclipse'
apply plugin: 'idea'
apply plugin: 'jacoco'

// This allows you to "Build and run using IntelliJ IDEA", an option in IDEA's Settings.
idea {
Expand Down
9 changes: 9 additions & 0 deletions chessevolved_model/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,13 @@ dependencies {
implementation("io.github.cdimascio:dotenv-kotlin:6.5.1")

implementation project(":chessevolved_shared")

// Testing with kotlin.test and JUnit
testImplementation 'org.jetbrains.kotlin:kotlin-test'
testImplementation "org.jetbrains.kotlinx:kotlinx-coroutines-test:1.10.1"
}

test {
useJUnitPlatform()
workingDir = rootProject.file('assets').path
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package io.github.chessevolved.entities

import com.badlogic.ashley.core.Engine
import com.badlogic.gdx.assets.AssetManager
import com.badlogic.gdx.scenes.scene2d.Stage
import io.github.chessevolved.data.Position
import io.github.chessevolved.enums.PlayerColor
import io.github.chessevolved.enums.WeatherEvent
import io.github.chessevolved.singletons.EcsEngine
import org.junit.jupiter.api.Test
import kotlin.test.assertFails

class BoardSquareFactoryTest {
private val engine: Engine = EcsEngine
private val assetManager: AssetManager = AssetManager()
private val boardSquareFactory: BoardSquareFactory = BoardSquareFactory(engine, assetManager)

/**
* Attempt to create a square at an invalid location
*/
@Test
fun createBoardSquare() {
assertFails({
boardSquareFactory.createBoardSquare(
Position(1000, 1000),
WeatherEvent.NONE,
PlayerColor.BLACK,
Stage(),
)
})
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
package io.github.chessevolved.entities

import com.badlogic.ashley.core.Engine
import com.badlogic.gdx.assets.AssetManager
import com.badlogic.gdx.scenes.scene2d.Stage
import io.github.chessevolved.data.Position
import io.github.chessevolved.enums.PlayerColor
import io.github.chessevolved.singletons.EcsEngine
import org.junit.jupiter.api.Test
import kotlin.test.assertFails

class PieceFactoryTest {
private val engine: Engine = EcsEngine
private val assetManager: AssetManager = AssetManager()
private val pieceFactory: PieceFactory = PieceFactory(engine, assetManager)

/**
* Attempt to create a pawn at an invalid location
*/
@Test
fun createPawn() {
assertFails({
pieceFactory.createPawn(
false,
Position(1000, 1000),
PlayerColor.BLACK,
Stage(),
)
})
}

/**
* Attempt to create a knight at an invalid location
*/
@Test
fun createKnight() {
assertFails({
pieceFactory.createKnight(
Position(1000, 1000),
PlayerColor.BLACK,
Stage(),
)
})
}

/**
* Attempt to create a bishop at an invalid location
*/
@Test
fun createBishop() {
assertFails({
pieceFactory.createBishop(
Position(1000, 1000),
PlayerColor.BLACK,
Stage(),
)
})
}

/**
* Attempt to create a rook at an invalid location
*/
@Test
fun createRook() {
assertFails({
pieceFactory.createRook(
Position(1000, 1000),
PlayerColor.BLACK,
Stage(),
)
})
}

/**
* Attempt to create a queen at an invalid location
*/
@Test
fun createQueen() {
assertFails({
pieceFactory.createQueen(
Position(1000, 1000),
PlayerColor.BLACK,
Stage(),
)
})
}

/**
* Attempt to create a king at an invalid location
*/
@Test
fun createKing() {
assertFails({
pieceFactory.createKing(
Position(1000, 1000),
PlayerColor.BLACK,
Stage(),
)
})
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package io.github.chessevolved.singletons

import io.github.chessevolved.dtos.SettingsDto
import org.junit.jupiter.api.Assertions.assertEquals
import kotlin.test.Test

class GameSettingsTest {
@Test
fun isFOWEnabled() {
assertEquals(false, GameSettings.isFOWEnabled())
}

@Test
fun getBoardSize() {
assertEquals(8, GameSettings.getBoardSize())
}

@Test
fun getGameSettings() {
val settingsDTO: SettingsDto = SettingsDto(false, 8)
assertEquals(settingsDTO, GameSettings.getGameSettings())
}

@Test
fun setGameSettings() {
val settingsDTO: SettingsDto = SettingsDto(true, 16)
GameSettings.setGameSettings(settingsDTO)
assertEquals(settingsDTO, GameSettings.getGameSettings())
assertEquals(true, GameSettings.isFOWEnabled())
assertEquals(16, GameSettings.getBoardSize())
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package io.github.chessevolved.singletons

import kotlinx.coroutines.test.runTest
import org.junit.jupiter.api.Assertions.assertFalse
import kotlin.test.Test
import kotlin.test.assertFails

class GameTest {
suspend fun joinGame() {
Game.joinGame("HY76UYTERFRGET")
}

/**
* Attempt to join a game that does not exists
*/
@Test
fun testJoinGame() =
runTest { // Required to test suspend functions
assertFails({ joinGame() })
}

suspend fun leaveGame() {
Game.leaveGame()
}

/**
* Attempt to leave a game despite not being in a game
*/
@Test
fun testLeaveGame() =
runTest {
assertFails({ leaveGame() })
}

suspend fun askForRematch() {
Game.askForRematch()
}

/**
* Attempt to ask for a rematch despite not being in a game
*/
@Test
fun testAskForRematch() =
runTest {
assertFails({ askForRematch() })
}

@Test
fun getWantsRematch() {
assertFalse(Game.getWantsRematch())
}

@Test
fun isInGame() {
assertFalse(Game.isInGame())
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
package io.github.chessevolved.singletons

import kotlinx.coroutines.test.runTest
import org.junit.jupiter.api.assertThrows
import kotlin.test.Test
import kotlin.test.assertFails

class LobbyTest {
suspend fun joinLobby() {
Lobby.joinLobby("E6U5Y5GTRFEZE45")
}

/**
* Attempt to join a lobby that does not exists
*/
@Test
fun testJoinLobby() =
runTest { // Required to test suspend functions
assertFails({ joinLobby() })
}

suspend fun joinRematchLobbyAsHost() {
Lobby.joinRematchLobbyAsHost()
}

/**
* Attempt to join a rematch lobby as a host that does not exists
*/
@Test
fun testJoinRematchLobbyAsHost() =
runTest { // Required to test suspend functions
assertFails({ joinRematchLobbyAsHost() })
}

suspend fun joinRematchLobbyNonHost() {
Lobby.joinRematchLobbyNonHost()
}

/**
* Attempt to join a rematch lobby as a non-host that does not exists
*/
@Test
fun testJoinRematchLobbyNonHost() =
runTest { // Required to test suspend functions
assertFails({ joinRematchLobbyNonHost() })
}

suspend fun leaveLobby() {
Lobby.leaveLobby()
}

/**
* Attempt to leave a lobby despite not being in a lobby
*/
@Test
fun testLeaveLobby() =
runTest { // Required to test suspend functions
assertFails({ leaveLobby() })
}

suspend fun leaveLobbyWithoutUpdating() {
Lobby.leaveLobbyWithoutUpdating()
}

/**
* Attempt to leave a lobby as a second player despite not being in a lobby
*/
@Test
fun testLeaveLobbyWithoutUpdating() =
runTest { // Required to test suspend functions
assertFails({ leaveLobbyWithoutUpdating() })
}

suspend fun setLobbySettings() {
Lobby.setLobbySettings()
}

/**
* Attempt to change lobby settings despite not being in a lobby
*/
@Test
fun testSetLobbySettings() =
runTest { // Required to test suspend functions
assertThrows<IllegalStateException>({ setLobbySettings() })
}
}
7 changes: 7 additions & 0 deletions chessevolved_presenter/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,11 @@ dependencies {
implementation project(":chessevolved_model")
implementation project(":chessevolved_view")
implementation project(":chessevolved_shared")

// Testing with kotlin.test and JUnit
testImplementation 'org.jetbrains.kotlin:kotlin-test'
}

test {
useJUnitPlatform()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package io.github.chessevolved.presenters

import com.badlogic.gdx.graphics.g2d.SpriteBatch
import io.github.chessevolved.Navigator
import io.github.chessevolved.views.IView

class MockPresenter(
private val view: IView,
private val navigator: Navigator,
) : IPresenter {
override fun render(sb: SpriteBatch) {
}

override fun resize(
width: Int,
height: Int,
) {
}

override fun dispose() {
}

override fun setInputProcessor() {
}
}
Loading