I created something: https://github.com/BraisGabin/detekt-junit-rules It's a rule set to avoid common mistakes while using JUnit. Right now it just have one rule but it's an important one: did you know that if your
@Test
function doesn't return
Unit
JUnit will not execute it? But, no one returns something in those functions, right? Well... if you uses coroutines and follow this pattern in your tests:
@Test fun foo() = runBlocking { ... }
your tests are not executed at all. Give the custom rule a try if you want 🙂. All feedback is more than welcome.
🎉 7
😮 2
e
ephemient
08/31/2021, 7:29 PM
does this use/require type resolution? because
Copy code
@Test
fun test() = run {
assertTrue(true)
}
should be ok
b
Brais Gabin
09/01/2021, 6:20 AM
Yes, it does. The rule only works with Type resolution. And yes, that code is fine and it's not flagged.
👍 1
m
marschwar
09/23/2021, 10:35 AM
Playing devils advocate here 😉 This rule in ArchUnit would look like this:
Copy code
@AnalyzeClasses(packages = "<http://com.company.my|com.company.my>")
class ArchUnitTest {
@ArchTest
val returnVoidRule = methods()
.that().areAnnotatedWith(Test.class)
.should().haveRawReturnType("void");
}
Since junit obviously is used in your case, it would be really simple to set it up.
b
Brais Gabin
09/24/2021, 1:12 PM
I didn't know ArchUnit. That api looks so cool! It's so easy to read!