b

    Brais Gabin

    1 year ago
    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.
    e

    ephemient

    1 year ago
    does this use/require type resolution? because
    @Test
    fun test() = run {
        assertTrue(true)
    }
    should be ok
    b

    Brais Gabin

    1 year ago
    Yes, it does. The rule only works with Type resolution. And yes, that code is fine and it's not flagged.
    marschwar

    marschwar

    1 year ago
    Playing devils advocate here 😉 This rule in ArchUnit would look like this:
    @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

    1 year ago
    I didn't know ArchUnit. That api looks so cool! It's so easy to read!