Skip to content

Instantly share code, notes, and snippets.

@nikialeksey
Last active October 9, 2018 10:37
Show Gist options
  • Save nikialeksey/8db7cf365e153e784b916ad26ada256d to your computer and use it in GitHub Desktop.
Save nikialeksey/8db7cf365e153e784b916ad26ada256d to your computer and use it in GitHub Desktop.
Run detekt in unit test
dependencies {
testImplementation "io.gitlab.arturbosch.detekt:detekt-core:1.0.0.RC9.2"
testImplementation "io.gitlab.arturbosch.detekt:detekt-rules:1.0.0.RC9.2"
}
package app.package.name
import io.gitlab.arturbosch.detekt.api.Finding
import io.gitlab.arturbosch.detekt.api.YamlConfig
import io.gitlab.arturbosch.detekt.core.DetektFacade
import io.gitlab.arturbosch.detekt.core.ProcessingSettings
import io.gitlab.arturbosch.detekt.rules.providers.*
import org.hamcrest.core.IsEqual
import org.junit.Assert
import org.junit.Test
import java.nio.file.Paths
class StaticAnalysis {
@Test
fun detekt() {
val detektion = DetektFacade.create(
ProcessingSettings(
Paths.get("../"),
YamlConfig.load(Paths.get("./src/test/assets/detekt.yml"))
),
listOf(
StyleGuideProvider(),
ComplexityProvider(),
EmptyCodeProvider(),
NamingProvider(),
PerformanceProvider(),
PotentialBugProvider(),
CommentSmellProvider(),
ExceptionsProvider()
),
emptyList()
).run()
val errors = detektion.findings.entries.map { it.value.size }.sum()
val message = detektion.findings.entries.joinToString("\n") {
it.value.joinToString("\n", transform = Finding::toString)
}
Assert.assertThat(message, errors, IsEqual.equalTo(0))
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment