Robolectric 2.x - dependent jars are downloading while running the tests - robolectric

How will I download all the robolectric dependent jars, to avoid runtime downloading and make it offline? I need to use Robolectric.buildActivity(), which is part of 2.x.x versions.
any idea on this ?

Starting with Robolectric 2.4 they added two system properties to allow you to tell the Robolectric test runner to use local copies of the dependencies. See the Configuring Robolectric page.
The settings are:
robolectric.offline - Set to true to disable runtime fetching of jars
robolectric.dependency.dir - When in offline mode, specifies a folder containing runtime dependencies
One way to figure out which files you need to copy to the dependencyDir, is to run gradlew testDebug -i (or maybe with -d) and watch the output to see which jars are being downloaded at runtime. Then copy them to a known location on your build machine. (Another way to see which files you need, is to look at SdkConfig.java and get the dependency jars mentioned there along with their dependencies.)
For the current Robolectric 3.0-rc2, these are the files it needs:
accessibility-test-framework-1.0.jar
android-all-5.0.0_r2-robolectric-1.jar
icu4j-53.1.jar
json-20080701.jar
robolectric-annotations-3.0-rc2.jar
robolectric-resources-3.0-rc2.jar
robolectric-utils-3.0-rc2.jar
shadows-core-3.0-rc2.jar
sqlite4java-0.282.jar
tagsoup-1.2.jar
vtd-xml-2.11.jar
Copy these files to a known location, like say /home/jenkins/robolectric-files/, and then edit your build.gradle with something like this:
afterEvaluate {
project.tasks.withType(Test) {
systemProperties.put('robolectric.offline', 'true')
systemProperties.put('robolectric.dependency.dir', '/home/jenkins/robolectric-files/')
}
}

Here is how I solved it for org.robolectric:robolectric:3.0
https://gist.github.com/kotucz/60ae91767dc71ab7b444
I downloads the runtime dependencies into the build folder and configures the tests to use it - see setting the system properties.

I had this issue too, and found the cause to be the org.robolectric.Testrunner creating a org.robolectric.MavenCentral object, which declares a Maven repository using an Internet-url (Robolectric 2.3-release). Offline builds will not be able to access that url.
In my case I'm required to use a Maven repository proxy, so I replaced the url pointing to http://oss.sonatype.org with my local Maven repository proxy. That meant subclassing RobolectricTestRunner to org.robolectric.MyRobolectricTestRunner, and creating a custom MavenCentral object for it to use, and overriding the methods where RobolectricTestRunner references its private MAVEN_CENTRAL object.
The source code for RobolectricTestRunner and MavenCentral are available on Robolectric's Github page.

I used Robolectric version 3.0, and the dependency jars were downloaded from my repository, instead of sonatype.

Related

java.lang.module.FindException: Module test not foundIntellidea

I am have this Exception please help me!
"Error occurred during initialization of boot layer
java.lang.module.Find Exception: Module test not found"
But i write VM option "--module-path "D:\UT java\javafx-sdk-17.0.1\lib" --add-modules javafx.controls,javafx.fxml"
and i have module-info.java "
requires javafx.fxml;
requires javafx.controls;
requires javafx.graphics;
requires java.sql;
requires java.desktop;
requires jdk.jfr;"
i add my sdk. And if i create javafx demo project and execute him it work. and if i start change fxml file and change controller i have this exception.
I have IntellIJIdea 2021, javafx-sdk-17.0.1, jdbc jr 8,11,16
Steps to fix:
Delete the JavaFX sdk (you don’t need it).
Delete old Java versions (they are obsolete).
Update your IntelliJ IDE and IDE plugins to the most recent release, 2021.3.2+.
Create a new JavaFX project using JDK and JavaFX 17.0.2+.
Select Maven for the build system unless you know and prefer Gradle.
Do not set VM arguments, you don’t need them.
Adding modules via the --add-modules VM arguments is unnecessary when you have a valid module-info.java file.
The --module-path is still required so that the modules can be found, but Idea will provide the correct path for your modules automatically when it recognizes the modules through your Maven dependencies.
So you don't need to explicitly define the --module-path VM argument yourself for a Maven based build (that would be difficult to do anyway because the modules are all downloaded to different directories in your local maven repository).
Test it works following the Idea create new JavaFX project execution instructions.
Add additional modules one at a time by adding their maven dependency to pom.xml and the requires clause to module-info.java.
Ensure you synchronize the Maven and Idea projects between each
addition.
See, for example, this question on correctly adding the javafx.media module.
Adding other modules such as javafx.web, javafx.fxml or javafx.swing follows a similar pattern.
Test between each addition by building and running the project, to ensure you haven’t broken anything.
Copy your original source code into the appropriate package directories under the new project source directory:
src/main/java
Place resources in:
src/main/resources
following the Eden resource location guide.
Fix any errors, ensure everything compiles and runs, then test it.

How to override a JMetre plugin jar in a Blazemeter Run

I am trying to troubleshot an error I'm getting in Blazemeter for random-csv-data-set.
The btz.log from the Blazemeter Test run shows the below line...
2021-02-10 10:14:52,518 INFO o.j.r.JARSourceHTTP: Downloading: https://search.maven.org/remotecontent?filepath=com/blazemeter/jmeter-plugins-random-csv-data-set/0.7/jmeter-plugins-random-csv-data-set-0.7.jar
Which could be the point it downloads the jar (latest one?) for the required plugins for my test.
And during the test I am getting an exception from one of the classes in the plugin jar.
I have cloned the plugin project (opensource) and started adding some debug lines and compiled a new jar version.
I was advised If I upload the plugin jar along with my tests files to Blazemeter, the uploaded jar should be taken in for the run. But I still see the exception from the old line numbers which means its still referring to the original jar version 0.7.
How can I override this with my version of the plugin?
I believe you should ask this type of questions via BlazeMeter Support as I doubt that everyone here is fully aware of what's going on there
Whatever.
Looking into Taurus documentation it looks like that Random CSV Data Set Config is being detected and automatically downloaded using JMeter Plugins Manager so in order to prevent Taurus from downloading the "vanilla" version of the plugin which doesn't contain your changes you need to add the following line to your Taurus YAML file:
modules:
jmeter:
detect-plugins: false

opendaylight: using external jar file

I am developing an application on opendaylight Carbon (based on Karaf). I need to use a library (specifically dnsjava) in my bundle. How do I go about including this?
I tried the following which did not work:
In my features/pom.xml, I included a mvn dependency for my jar file.
In my features/src/main/features/features.xml, I added a bundle:
<bundle>wrap:mvn:dnsjava/dnsjava/${dnsjava.version}</bundle>
However, I still have an error when I go to start my feature:
Error executing command: Error executing command on bundles:
Unable to execute command on bundle 278: The bundle "gov.nist.sdnmud.impl_0.1.0.SNAPSHOT [278]" could not be resolved. Reason: Missing Constraint: Import-Package: org.xbill.DNS; version="[2.1.0,3.0.0)"
Thanks for any help.
I'm not an expert, but if the artifact doesn't have OSGi properties in the jar, which is likely why you've added the "wrap" prefix, then you have to manually set the required OSGi properties on the features.xml dependency line, in an odd microformat syntax.
In our environment, we have to do something like this:
wrap:mvn:<group>/<artifact>/<version>$Bundle-SymbolicName=<bundlename>&Bundle-Version=<version>
This issue doesn't have anything to do with opendaylight.

Add JavaFX (of JDK8) in sbt (using the play framework)

The goal is to have a standalone Play Framework (2.2) application having an additional status window open containing some javafx (javafx-8) elements.
Since JavaFX classes are now on the default runtime classpath for an Oracle Java 8 implementation using javafx.* in my classes and compiling with sbt should just be fine.
However sbt can't find these classes and quits with
play.api.UnexpectedException: Unexpected exception[NoClassDefFoundError: javafx/application/Application]
when executing
..\path-to-play-framework-2.2\play project run
The best way to fix this problem seems to be the modification of build.sbt in the project directory. What can I do to add the missing (class) path?
Sadly JavaFX doesn't link that easily to an sbt build. You need to set your JAVA_HOME environment variable and do modifications to your build file.
Here I have a repository where this is set up. The important bit if you are using an sbt build rather than a scala build is this one:
unmanagedJars in Compile += Attributed.blank(
file(System.getenv("JAVA_HOME") + "/jre/lib/jfxrt.jar")),
fork in run := true
The reason for this is that jfxrt.jar is the archive containing the JavaFX runtime and it is not included in the classpath of an sbt project by default.
Anotherway is to set the Classpath for sbt. This can be done on the machines which can't resolve JavaFX.
SBT_OPTS="-Xbootclasspath/p:/usr/share/java/openjfx/jre/lib/ext/jfxrt.jar"

Py2app does not include the Sqlite driver- "Database error: Driver not loaded Driver not loaded"

I am having the same issue described in this post on the py2app mailing list.
I have a python application that uses a sqlite database. On my machine, which has all the dependencies installed, there are no issues. However, when I bundle the application with py2app, clicking a menu that causes the database to be accessed results in this error:
Database error: Driver not loaded Driver not loaded
For the Windows installer, the files in \Qt\version\plugins\sqldrivers\*.* can be copied to \myApp\sqldrivers\*
The same files on the Mac can be found in /opt/local/share/qt4/plugins/sqldrivers (installed via Macports).
However, copying the sqldrivers directory to my application's Resources or Frameworks directories still results in the same error.
How can I add sqlite support into my application that is built using py2app?
Turns out the pyside recipe does have a way to specify which qt-plugins you need...
options=dict(py2app={
'argv_emulation': True,
'qt_plugins' : "sqldrivers",
}
),
This puts all the sqldrivers into the right directory and setups qt.conf correctly.
have you tried what he said
in this post ?
py2app setup.py usage question
it mentioned
you need to include the sqlalchemy.dialects.sqlite as a package
I managed to get this to work as follows:
After building with py2app, inside the application's Contents directory, make a new plugins directory.
Then copy sqldrivers/libqsqlite.dylib into this plugins directory.
Afterwards, install_name_tool has to be used to change the library links in libqsqlite.dylib to point to the Qt libraries in the application's Frameworks directory rather than the system Qt libraries.

Resources