Code Monkey home page Code Monkey logo

Comments (15)

mannodermaus avatar mannodermaus commented on May 25, 2024

Addressed in 1.0.0-M4-rev2.

from android-junit5.

jschamburger avatar jschamburger commented on May 25, 2024

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 ClassNotFoundExceptions 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.

mannodermaus avatar mannodermaus commented on May 25, 2024

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.

jschamburger avatar jschamburger commented on May 25, 2024

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.

mannodermaus avatar mannodermaus commented on May 25, 2024

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.

jschamburger avatar jschamburger commented on May 25, 2024

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.

mannodermaus avatar mannodermaus commented on May 25, 2024

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.

jschamburger avatar jschamburger commented on May 25, 2024

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.

mannodermaus avatar mannodermaus commented on May 25, 2024

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.

mannodermaus avatar mannodermaus commented on May 25, 2024

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.

jschamburger avatar jschamburger commented on May 25, 2024

Using that dependency, the tests are running fine in AS and on command-line.

from android-junit5.

mannodermaus avatar mannodermaus commented on May 25, 2024

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.

jschamburger avatar jschamburger commented on May 25, 2024

Great, thank you for all the work on this plugin!

from android-junit5.

mannodermaus avatar mannodermaus commented on May 25, 2024

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.

mannodermaus avatar mannodermaus commented on May 25, 2024

Addressed in 1.0.0-M4-rev3.

from android-junit5.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.