Is there a way i could call a gradle task from within the java program - android-studio

I want the android app that is being tested to be uninstalled everytime a new test method in the class runs. I know that gradle uninstallAll task does this. But i would like to call this task from the setup method of the testcase class.

Related

Debugging gradle build file that uses Kotlin DSL

Is it possible to debug a gradle build file that is written using Kotlin DSL? A google search doesn't really show anything. By debugging, I'm really talking about using breakpoints that let you step into the gradle file and execute each line and inspect variables.

java.lang.NoClassDefFoundError: androidx/sqlite/db/SupportSQLiteQuery in unit test that worked yesterday

The answer to this question is not "Android unit tests cannot access Android stack modules such as the Room database because on your desktop they are all stubbed out."
I had a bunch of unit tests that tested static methods that happened to be inside a Dao class - call it FooDao. They all passed for a year until today, when they stopped passing when the Android Studio editor calls them. They still pass when the command line tests call them, but the editor reports:
java.lang.NoClassDefFoundError: androidx/sqlite/db/SupportSQLiteQuery
This happens when the unit test gets to FooDao.innocentStaticMethod(). Like I said, accessing the FooDao class without invoking any of its real Room methods formerly worked in unit tests.
The long-term fix is to refactor my code so FooDao only contains real Room calls. But why did Android Studio's test runner suddenly stop working? The version is Android Studio 4.2 RC 1, built on March 23, 2021. And targetSdkVersion 30.
Switching from androidx.room:room-runtime:2.2.6 and compiler to 2.3.0 did it, on April 22th.
In app/build.gradle:
implementation 'androidx.room:room-runtime:2.2.6'
annotationProcessor 'androidx.room:room-compiler:2.2.6'
So while I leave a band-aid on the problem until the next time we need to upgrade my mighty FooDao, could someone ping Android central about this? ktx

How does dalvikvm understand the starting point of android application

I can successfully run a simple java program in dalvikvm by converting the java class into dex file. But when I try to run android application by converting its class files into dex, it says static main(String args[]) not found.
Android application does not contain static main() method.
So where does dalvikvm start executing an android application or how does it find the static main() method in android application???
Android determines your app's entry point based on the AndroidManifest.xml shipped with your app. Specifically, Android determines which intent was sent to the app (to cause it to launch), and will instantiate the appropriate Activity and call its onCreate method. This creation process is overseen by a wrapper process called app_process, which calls into dalvik directly and sets up the app execution environment.
Dalvik itself behaves like a normal Java JVM in most regards; therefore, running a jar or dex with Dalvik will still expect a main method, as with normal Java.

worklight adapters and Groovy

Has anyone had success implementing IBM Worklight 5.0.6 Adapters using the Groovy language? Ie. Instead of calling a Java class from the JS adapter call a Groovy class. We have tried this and it seems to work most of the time but randomly we will get strange errors when invoking an adapter procedure. Ie.
Failed to create DGM method proxy : java.lang.NoSuchMethodException: org.codehaus.groovy.runtime.dgm$24.<init>(java.lang.String, org.codehaus.groovy.reflection.CachedClass, java.lang.Class, [Ljava.lang.Class;)
FWLSE0101E: Caused by: java.lang.NoSuchMethodException: org.codehaus.groovy.runtime.dgm$24.<init>(java.lang.String, org.codehaus.groovy.reflection.CachedClass, java.lang.Class, [Ljava.lang.Class;)
Unit tests executing the Groovy code run fine within Eclipse and the Groovy code seems to be compiling fine down to .class files and included in the adapter package. We're wondering if this is an issue with Groovy itself or invoking Groovy within the Worklight server container. I believe Worklight is using Rhino behind the scenes which may also be a culprit?
We are using Groovy 2.1.5 and the Eclipse plugin 2.8
did you open the .war and check if all compiled classes and libraries are actually in there?
We had the case quite often that the WL Eclipse Plugin/Build did not compile and package our Java Classes for the Adapter in the "server" folder ... they were missing in the .war file that we deployed and we got all sorts of Rhino, ClassNotFound etc. errors.
In addition to previous answer. You can always force a rebuild by selecting the project in the Enterprise Explorer or Navigator views, then select menu Project -> Clean -> Clean Projects Selected Below (the only choice should be your project).
This will clean the binaries, then rebuild your entire project.

How can I run VS2012 CppUnitTestFramework unit tests from an msbuild script?

I've written a native unit test dll that uses VS2012's CppUnitTestFramework. I can run these tests in the VS2012's IDE in the Test Explorer window.
But, I'd like to also run these tests from our MsBuild script. I guess I need to launch some test runner exe with appropriate command line, but am struggling to find information on this.
Can you help point me in the right direction. Thanks.
The Visual Studio Test Runner is a simple command line tool which needs to be called in order to find and execute the tests. Creating a small msbuild task or using the standard exec task would be enough to invoke the tests after the build.
As long as the test runner is installed properly, it should just pick up these tests and execute them.
See this blog post explaining all the command line intricacies of the new vstest.console.exe.

Resources