Skip to content

Commit

Permalink
Merge pull request #207 from swm-standard/seyeon/swm-170
Browse files Browse the repository at this point in the history
Test: jacoco test coverage์— ๋งž๊ฒŒ ํ…Œ์ŠคํŠธ ์ฝ”๋“œ ์ž‘์„ฑ
  • Loading branch information
adorableco authored Sep 10, 2024
2 parents 85aac61 + e97038c commit c576c3a
Show file tree
Hide file tree
Showing 10 changed files with 175 additions and 20 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/develop-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ jobs:
run: chmod +x gradlew

- name: Test with Gradle
run: ./gradlew clean build test
run: ./gradlew clean build jacocoTestReport

- name: Publish Unit Test Results
uses: EnricoMi/publish-unit-test-result-action@v1
Expand Down
8 changes: 5 additions & 3 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ dependencies {
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.9.0-RC")
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-reactor:1.9.0-RC")
implementation("org.springframework.boot:spring-boot-starter-webflux")
testImplementation("com.navercorp.fixturemonkey:fixture-monkey-kotlin:1.0.23")

// querydsl
implementation("com.querydsl:querydsl-jpa:5.0.0:jakarta")
Expand All @@ -90,7 +91,6 @@ kotlin {

tasks.withType<Test> {
useJUnitPlatform()
finalizedBy("jacocoTestReport")
}

tasks.test {
Expand Down Expand Up @@ -160,6 +160,7 @@ tasks.jacocoTestReport {
"**/repository/*",
"**/common/*",
"**/*PhoteApplication*",
"**/entity/*RefreshToken*",
) + qDomains

classDirectories.setFrom(
Expand All @@ -179,13 +180,13 @@ tasks.jacocoTestCoverageVerification {
limit {
counter = "BRANCH"
value = "COVEREDRATIO"
minimum = 0.00.toBigDecimal()
minimum = 0.50.toBigDecimal()
}

limit {
counter = "METHOD"
value = "COVEREDRATIO"
minimum = 0.00.toBigDecimal()
minimum = 0.40.toBigDecimal()
}

val qDomains = emptyList<String>().toMutableList()
Expand All @@ -204,6 +205,7 @@ tasks.jacocoTestCoverageVerification {
"**.repository.*",
"**.common.*",
"**.*PhoteApplication*",
"**.entity.*RefreshToken*",
) + qDomains
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.swm_standard.phote.common.module

class Qualifier {
@MustBeDocumented
@Retention(AnnotationRetention.RUNTIME)
@Target(AnnotationTarget.TYPE, AnnotationTarget.FUNCTION, AnnotationTarget.PROPERTY_GETTER)
annotation class Generated
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ data class QuestionSet(
}

companion object {
fun createSequence(
fun createQuestionSet(
question: Question,
workbook: Workbook,
nextSequence: Int,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ class WorkbookService(
): Int {
if (!questionSetRepository.existsByQuestionIdAndWorkbookId(question.id, workbook.id)
) {
questionSetRepository.save(QuestionSet.createSequence(question, workbook, sequence))
questionSetRepository.save(QuestionSet.createQuestionSet(question, workbook, sequence))
return sequence + 1
}

Expand Down
67 changes: 54 additions & 13 deletions src/test/kotlin/com/swm_standard/phote/entity/AnswerTest.kt
Original file line number Diff line number Diff line change
@@ -1,10 +1,19 @@
package com.swm_standard.phote.entity

import org.junit.jupiter.api.Assertions
import com.navercorp.fixturemonkey.FixtureMonkey
import com.navercorp.fixturemonkey.kotlin.KotlinPlugin
import com.navercorp.fixturemonkey.kotlin.giveMeOne
import org.assertj.core.api.Assertions
import org.junit.jupiter.api.Test
import java.util.UUID

class AnswerTest {
private val fixtureMonkey: FixtureMonkey =
FixtureMonkey
.builder()
.plugin(KotlinPlugin())
.build()

@Test
fun `๋ฌธ์ œ๊ฐ€ ๊ฐ๊ด€์‹์ด๋ฉด ์ •์˜ค๋‹ต ์ฒดํฌํ•œ๋‹ค`() {
val category = Category.MULTIPLE
Expand All @@ -14,29 +23,41 @@ class AnswerTest {

answer.checkMultipleAnswer()

Assertions.assertEquals(submittedAnswer == correctAnswer, answer.isCorrect)
Assertions.assertFalse(answer.isCorrect)
Assertions.assertThat(submittedAnswer == correctAnswer).isEqualTo(answer.isCorrect)
Assertions.assertThat(answer.isCorrect).isFalse()
}

@Test
fun `์ œ์ถœํ•œ ๋‹ต์•ˆ์„ ์ƒ์„ฑํ•œ๋‹ค`() {
val exam = createExam()
val submittedAnswer = "1"
val question = createQuestion(answer = submittedAnswer)
val sequence = 2

val createAnswer =
Answer.createAnswer(
question = question,
exam = exam,
submittedAnswer = submittedAnswer,
sequence = sequence,
)

Assertions.assertThat(createAnswer.submittedAnswer).isEqualTo(submittedAnswer)
Assertions.assertThat(createAnswer.exam).isEqualTo(exam)
Assertions.assertThat(createAnswer.sequence).isEqualTo(sequence)
}

fun createWorkbook(): Workbook =
Workbook(
title = "hinc",
description = null,
member = createMember(),
member = fixtureMonkey.giveMeOne(),
emoji = "๐Ÿ“š",
)

fun createMember(): Member =
Member(
name = "Mayra Payne",
email = "[email protected]",
image = "dicant",
provider = Provider.APPLE,
)

fun createExam() =
Exam(
member = createMember(),
member = fixtureMonkey.giveMeOne(),
workbook = createWorkbook(),
sequence = 4282,
time = 40,
Expand Down Expand Up @@ -69,4 +90,24 @@ class AnswerTest {
submittedAnswer = submittedAnswer,
sequence = 2017,
)

private fun createQuestion(answer: String) =
Question(
id = UUID.randomUUID(),
member =
Member(
name = "Charmaine Joseph",
email = "[email protected]",
image = "maiorum",
provider = Provider.APPLE,
),
statement = "Missouri",
options = null,
image = null,
answer = answer,
category = Category.MULTIPLE,
questionSet = listOf(),
tags = mutableListOf(),
memo = null,
)
}
2 changes: 1 addition & 1 deletion src/test/kotlin/com/swm_standard/phote/entity/ExamTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class ExamTest {
val exam = Exam.createExam(member, workbook, sequence, time)

Assertions.assertThat(exam.workbook).isEqualTo(workbook)
Assertions.assertThat(exam.member).isEqualTo(member)
Assertions.assertThat(exam.member.name).isEqualTo(member.name)
Assertions.assertThat(exam.sequence).isEqualTo(sequence)
}

Expand Down
52 changes: 52 additions & 0 deletions src/test/kotlin/com/swm_standard/phote/entity/QuestionSetTest.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package com.swm_standard.phote.entity

import com.navercorp.fixturemonkey.FixtureMonkey
import com.navercorp.fixturemonkey.api.introspector.ConstructorPropertiesArbitraryIntrospector
import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Test

class QuestionSetTest {
private val fixtureMonkey: FixtureMonkey =
FixtureMonkey
.builder()
.objectIntrospector(ConstructorPropertiesArbitraryIntrospector.INSTANCE)
.build()

@Test
fun `questionSet์˜ ์ˆœ์„œ๋ฅผ ๋ณ€๊ฒฝํ•˜๋Š”๋ฐ ์„ฑ๊ณตํ•œ๋‹ค`() {
val questionSet = fixtureMonkey.giveMeOne(QuestionSet::class.java)
val newSequence = 4

questionSet.updateSequence(newSequence)

assertEquals(newSequence, questionSet.sequence)
}

@Test
fun `questionSet์„ ์ƒ์„ฑํ•˜๋Š”๋ฐ ์„ฑ๊ณตํ•œ๋‹ค`() {
val question = createQuestion()
val workbook = fixtureMonkey.giveMeOne(Workbook::class.java)
val newSequence = 1

val questionSet =
QuestionSet.createQuestionSet(
question = question,
workbook = workbook,
nextSequence = newSequence,
)

assertEquals(newSequence, questionSet.sequence)
assertEquals(workbook, questionSet.workbook)
assertEquals(question, questionSet.question)
}

private fun createQuestion(): Question =
Question(
member = Member("phote", "[email protected]", "image", Provider.KAKAO),
statement = "๋ชจ๋“  ๊ฐ์ด ๋™์ผํ•œ ์‚ผ๊ฐํ˜•์€?",
image = "http://example.com/image.jpg",
answer = "์ •์‚ผ๊ฐํ˜•",
category = Category.ESSAY,
memo = "์‚ผ๊ฐํ˜• ๋‚ด๊ฐ์˜ ํ•ฉ์€ 180๋„์ด๋‹ค.",
)
}
51 changes: 51 additions & 0 deletions src/test/kotlin/com/swm_standard/phote/entity/QuestionTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,20 @@ package com.swm_standard.phote.entity

import com.fasterxml.jackson.databind.JsonNode
import com.fasterxml.jackson.databind.ObjectMapper
import com.navercorp.fixturemonkey.FixtureMonkey
import com.navercorp.fixturemonkey.kotlin.KotlinPlugin
import com.navercorp.fixturemonkey.kotlin.giveMeOne
import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Test
import java.util.UUID

class QuestionTest {
private val fixtureMonkey: FixtureMonkey =
FixtureMonkey
.builder()
.plugin(KotlinPlugin())
.build()

private fun createQuestion(): Question {
val objectMapper = ObjectMapper()
val jsonString = """
Expand All @@ -27,6 +37,32 @@ class QuestionTest {
answer = "1",
category = Category.MULTIPLE,
memo = "์‚ผ๊ฐํ˜•์€ ๊ผญ์ง“์ ์ด 3๊ฐœ๋‹ค",
tags =
mutableListOf(
Tag(
id = 1,
name = "์ˆ˜ํ•™",
question =
Question(
id = UUID.randomUUID(),
member =
Member(
name = "Luella Kline",
email = "[email protected]",
image = "et",
provider = Provider.APPLE,
),
statement = "Louisiana",
options = null,
image = null,
answer = "hac",
category = Category.MULTIPLE,
questionSet = listOf(),
tags = mutableListOf(),
memo = null,
),
),
),
)
}

Expand All @@ -42,4 +78,19 @@ class QuestionTest {
val expectedList = listOf("์‚ผ๊ฐํ˜•", "์‚ฌ๊ฐํ˜•", "๋งˆ๋ฆ„๋ชจ", "ํ‰ํ–‰์‚ฌ๋ณ€ํ˜•", "์›")
assertEquals(expectedList, deserializedOptions)
}

@Test
fun `๊ณต์œ ๋ฐ›์€ ๋ฌธ์ œ๋ฅผ ๋ณต์‚ฌํ•ด์„œ ์ €์žฅํ•œ๋‹ค`() {
val questions = listOf(createQuestion(), createQuestion(), createQuestion())
// val questions = fixtureMonkey.giveMeBuilder<Question>().size(Question::tags, 0).sampleList(5)
val member: Member = fixtureMonkey.giveMeOne()

val sharedQuestions = Question.createSharedQuestions(questions, member)

assertEquals(sharedQuestions.size, questions.size)
assertEquals(sharedQuestions[0].member, member)
assertEquals(sharedQuestions[2].answer, questions[2].answer)
assertEquals(sharedQuestions[1].tags[0].name, questions[1].tags[0].name)
assertEquals(sharedQuestions[1].tags[0].id, questions[1].tags[0].id)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class WorkbookTest {

Assertions.assertThat(workbook.title).isEqualTo(testTitle)
Assertions.assertThat(workbook.emoji).isEqualTo("โž—")
Assertions.assertThat(workbook.member.email).isEqualTo(member.email)
}

@Test
Expand Down

0 comments on commit c576c3a

Please sign in to comment.