Comments (15)
Addressed in 1.0.0-M4-rev2.
from android-junit5.
Unfortunately, I still have problems (with 1.0.0-M4-rev2) regarding classpath when starting tests (for now, I only have legacy JUnit 4 tests) from Android Studio (tried both 2.4 and 3.0 Canary 3). From the command-line, the tests run just fine, but in Android Studio, I get ClassNotFoundException
s for net.sqlcipher.database.SQLiteOpenHelper
and com.roughike.bottombar.OnTabClickListener
(library dependency). The setup in the README.MD should be enough, right?
from android-junit5.
Thanks for reporting back. Are you on AGP 2.x or 3.x when you run into this? Does changing to the other work? I'm going to investigate further.
from android-junit5.
Thanks! I tried it with Android Studio 2.4 Preview and 3.0 Canary 3; both didn't work.
But the problem might be caused by a dependency aar in a separate module. I'll investigate some more, maybe the issue is in my setup.
I tried running the sample project https://github.com/StylingAndroid/JUnit5/tree/Kotlin with updated dependency and it worked just fine.
from android-junit5.
I'm seeing the same inconsistent behavior between different projects as well, although it's usually the cmd version that won't run, while the IDE is unaffected. I have looked into hooking into the default setup performed by the Android Gradle Plugin for unit tests directly, to leverage the classpath setup they've got going on. It isn't trivial though, since JUnit 5 relies on a JavaExec
task at the moment, which we'd need to combine with AGP's AndroidUnitTest
task type.
from android-junit5.
Alright, I just verified that the problem was caused by an .aar library which was imported as a separate module (using the steps described here https://stackoverflow.com/questions/29826717/how-to-import-a-aar-file-into-android-studio-1-1-0-and-use-it-in-my-code).
Importing the .aar file using a local repository fixed it and now all tests are running both in AS and on the command-line.
I added
repositories { flatDir { dirs 'libs' } }
on top level and
compile (name:'bottom-bar-release', ext:'aar')
to the dependencies.
I still get the warning about the net.sqlcipher.database.SQLiteOpenHelper
class not being found (apparently related to the GreenDao lib), but the tests are running.
It is worth noting that I also added the line
testProvided "org.junit.vintage:junit-vintage-engine:4.12.0-M4"
which I got from the StylingAndroid example.
from android-junit5.
I'm glad you got it working! As of 1.0.0-M4-rev1
, the Vintage Engine is supposed to be automatically applied to the runtime classpath when you apply the android-junit5
plugin. Can you verify that your tests still run if you remove the testProvided
dependency again?
from android-junit5.
Without the dependency, the tests are not running from Android Studio unfortunately:
Exception in thread "main" java.lang.NoClassDefFoundError: org/junit/platform/engine/EngineExecutionListener at org.junit.platform.launcher.core.LauncherFactory.create(LauncherFactory.java:53) at com.intellij.junit5.JUnit5IdeaTestRunner.createListeners(JUnit5IdeaTestRunner.java:39) at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:49) at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242) at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70) Caused by: java.lang.ClassNotFoundException: org.junit.platform.engine.EngineExecutionListener at java.net.URLClassLoader.findClass(URLClassLoader.java:381) at java.lang.ClassLoader.loadClass(ClassLoader.java:424) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331) at java.lang.ClassLoader.loadClass(ClassLoader.java:357) ... 5 more
On the command-line, they are running fine though.
Forgot to mention earlier: I'm using the Android Gradle Plugin 2.2.3.
from android-junit5.
Got it, thanks! I suppose the IDE requires the dependency to be available at compile time, too, even though a TestEngine
is supposed to be driving execution at runtime only - hence why the runtime dependency is not enough, and a compile-only dependency using provided
is necessary as well.
from android-junit5.
Actually, looking at the stack trace, it's not so much a class specific to the Vintage Engine that's failing, but the ExecutionListener itself.
Can you try changing the provided
dependency to org.junit.platform:junit-platform-engine:1.0.0-M4
instead, then try again?
from android-junit5.
Using that dependency, the tests are running fine in AS and on command-line.
from android-junit5.
I will amend the dependency issue for the next revision, so you won't have to add anything on top of what the plugin provides. Thanks for your efforts!
from android-junit5.
Great, thank you for all the work on this plugin!
from android-junit5.
Quick memo: Instead of trying to duplicate the work that the Gradle plugin does in terms of classpath aggregation, it would probably be way more reasonable to simply share the default test
tasks' classpath altogether. This should be fairly simple if we consider that Gradle's Test tasks expose their classpath publicly. Adding the junitPlatform
configuration at the end should do the trick...
from android-junit5.
Addressed in 1.0.0-M4-rev3.
from android-junit5.
Related Issues (20)
- Instrumented Testsuites run on JUnit4 Runner HOT 1
- Might be better to migrate CI to Github Actions
- Add support for Gradle Plugins DSL HOT 2
- org.junit.runners.model.InvalidTestClassError starting with Android Studio Dolphin | 2021.3.1 HOT 8
- Build broken when using kotlin 1.7.21 HOT 1
- Clarification with regards to JaCoCo HOT 2
- AGP 8.0.0-alpha10 HOT 6
- Various 'Unable to resolve' log messages for Android tests HOT 4
- Parallel concurrent execution of instrumentation tests HOT 6
- NoClassDefFoundError: org/jetbrains/kotlin/gradle/plugin/KotlinPluginKt with Kotlin 1.8.20 HOT 5
- `@Tag` at the class level results in test number mismatch HOT 6
- NoSuchMethodError: 'org.gradle.api.provider.Property org.gradle.api.reporting.ConfigurableReport.getOutputLocation()' on Gradle 7.5.1 HOT 3
- Is it possible to run junit5 tests with robolectric? HOT 5
- Encountering problems when trying to integrate the plugin HOT 1
- Log not working with ParameterizedTest HOT 1
- Support per-test log display for JUnit 5 instrumentation tests HOT 4
- Readme should include apply plugin for legacy syntax HOT 1
- "Expected N+1 tests, received N" caused by fun with @TestTemplate HOT 4
- Invalid test names for repeated and parametrized tests HOT 8
- Usage of ComposeExtension flags a false-positive warning in newer IDEs HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from android-junit5.