sergei-lapin / napt

Alternative to KAPT that skips Java stub generation and therefore is as efficient as Java APT but with Kotlin
MIT License
88 stars 6 forks source link

Junit5 @Nested tests not found #13

Closed zsweigart closed 1 year ago

zsweigart commented 1 year ago

I migrated to napt following the instructions in the README and after fixing the Hilt issue https://github.com/sergei-lapin/napt/issues/11 the app runs fine.

However my unit tests fail to compile because the tests in @Nested inner classes cannot be accessed

internal class TestClass {

  @Nested
  inner class `nested tests` {
    @Test
    fun `actual test`() {
        true
    }
  }
}

with an error

error: cannot access nested tests

Because I'm using Hilt, I do have the test compiler in my build.gradle file for the module but everything else is standard

testAnnotationProcessor deps.hilt.androidTestCompiler
sergei-lapin commented 1 year ago

Hi, @zsweigart! Are you using version 1.17? I've added ability of generation of trigger for all source sets (including tests) there.
You can enable it via

napt {
   additionalSourceSetsForTriggerGeneration.set(listOf("test"))
}

Not sure it's related, worth checking though

zsweigart commented 1 year ago

Yea I'm using 1.17 -

Is that closure supposed to be used within the android block? I'm getting a No signature of method: both in the android closure and outside of it

zsweigart commented 1 year ago

Ahh I see in the sample. So I was able to get it to sync, but I'm still getting the error: cannot access nested tests error

zsweigart commented 1 year ago

So, I'm not sure why this worked or changed anything but by changing the @Nested class name from

inner class `nested tests`

to

inner class NestedTest

worked

sergei-lapin commented 1 year ago

closing it then