Sample project that demonstrates issue during Spek2 execution from Android Studio if MockK library is used.
There are 3 test classes in the project: ExampleJUnit4Test
, ExampleJUnit5Test
and ExampleSpekTest
.
Each of them contain 2 tests – with and without mockk.
When tests are run from command line, everything is ok. However there is some weird behavior the tests are run tests from Android Studio.
Prerequisites
- Android studio 4.2 (but the issue will also reproduced on previous versions)
- Installed Spek Framework IDE plugin (2.0.16-IJ2020.2)
Scenario 1:
- Right-click on
ExampleSpekTest
- Click
Run 'Spek: com.example.sp...'
in the popup menu.
Expected: test runs ExampleSpekTest and passes
Actual: 1 test crashes with exception: java.lang.NoClassDefFoundError: io/mockk/proxy/MockKAgentFactory
Scenario 2:
- Right-click on
ExampleJUnit5Test
- Click
Run 'ExampleJUnit5Test'
in the popup menu.
Expected: Test runs ExampleJUnit5Test and passes
Actual: Both tests ExampleJUnit5Test and ExampleSpekTest run and both pass
Scenario 3:
- Right click on package
com.example.spek_mockk
or default package (test/java directory).
Expected: I should be able to run all tests in package
Actual: The option to run all tests is replaced with Run 'Speks in ...'
and it will only run Spek tests.
If the package doesn't have spek tests, the spek engine will crash.
This issues is reported here: spekframework/spek#837