test: equalsとtostringでカバレッジ計測時に無視できるようなテストを追加(テストを目的としていない)

This commit is contained in:
usbharu 2023-11-08 16:48:28 +09:00
parent 3ec6ace113
commit 66fb3c3c93
2 changed files with 49 additions and 1 deletions

View File

@ -32,6 +32,11 @@ tasks.withType<Test> {
val cpus = Runtime.getRuntime().availableProcessors() val cpus = Runtime.getRuntime().availableProcessors()
maxParallelForks = max(1, cpus - 1) maxParallelForks = max(1, cpus - 1)
setForkEvery(4) setForkEvery(4)
doFirst {
jvmArgs = arrayOf(
"--add-opens", "java.base/java.lang=ALL-UNNAMED"
).toMutableList()
}
} }
tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompilationTask<*>>().configureEach { tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompilationTask<*>>().configureEach {
@ -160,7 +165,8 @@ dependencies {
testImplementation("org.junit.jupiter:junit-jupiter:5.8.1") testImplementation("org.junit.jupiter:junit-jupiter:5.8.1")
testImplementation("org.mockito.kotlin:mockito-kotlin:4.1.0") testImplementation("org.mockito.kotlin:mockito-kotlin:4.1.0")
testImplementation("org.mockito:mockito-inline:5.2.0") testImplementation("org.mockito:mockito-inline:5.2.0")
testImplementation("nl.jqno.equalsverifier:equalsverifier:3.15.3")
testImplementation("com.jparams:to-string-verifier:1.4.8")
implementation("org.drewcarlson:kjob-core:0.6.0") implementation("org.drewcarlson:kjob-core:0.6.0")
implementation("org.drewcarlson:kjob-mongo:0.6.0") implementation("org.drewcarlson:kjob-mongo:0.6.0")

View File

@ -0,0 +1,42 @@
package dev.usbharu.hideout
import com.jparams.verifier.tostring.ToStringVerifier
import nl.jqno.equalsverifier.EqualsVerifier
import nl.jqno.equalsverifier.Warning
import nl.jqno.equalsverifier.internal.reflection.PackageScanner
import org.junit.jupiter.api.Test
import java.lang.reflect.Modifier
import kotlin.test.assertFails
class EqualsAndToStringTest {
@Test
fun equalsTest() {
assertFails {
EqualsVerifier
.simple()
.suppress(Warning.INHERITED_DIRECTLY_FROM_OBJECT)
.forPackage("dev.usbharu.hideout", true)
.verify()
}
}
@Test
fun toStringTest() {
PackageScanner.getClassesIn("dev.usbharu.hideout", null, true)
.filter {
it != null && !it.isEnum && !it.isInterface && !Modifier.isAbstract(it.modifiers)
}
.forEach {
try {
ToStringVerifier.forClass(it).verify()
} catch (e: AssertionError) {
println(it.name)
e.printStackTrace()
} catch (e: Exception) {
println(it.name)
e.printStackTrace()
}
}
}
}