Android instrumentation doesn't see my unit tests - android

I use http://code.google.com/p/the-missing-android-xml-junit-test-runner/ to run unit tests in jenkins environment.
One sample project worked well, but for another there are strange results.
Ant outputs
[echo] Running tests ...
[exec]
[exec] Test results for PolideaInstrumentationTestRunner=
[exec] Time: 0.0
[exec]
[exec] OK (0 tests)
[exec]
[exec]
and so does adb shell am instrument -w com.mypack.tests/pl.polidea.instrumentation.PolideaInstrumentationTestRunner.
It thinks that there are no tests but there are. They successfully run from eclipse.

The reason was:
in build.properties there was relative source.dir. Something like:
source.dir=src;./../../../other.package/src;./../../and.other/src
It compiled well, but prevented tests to run. When I set paths to absolute:
source.dir=${workspace}/my.package/src;${workspace}/other.package/src;${workspace}/and.other/src
tests do run.

Related

Flutter won't compile on ios nor android. Empty project wont compile

Soo... everything worked fine then after taking a break from work apps wont run.
New or empty project it does not matter.
Flutter doctor says everything is fine.
Here is Debug console.
Launching lib/main.dart on iPhone 14 Pro Max in debug mode...
lib/main.dart:1
Xcode build done. 3.8s
Failed to build iOS app
Error output from Xcode build:
↳
** BUILD FAILED **
Xcode's output:
↳
Writing result bundle at path:
/var/folders/bm/_wgnp7b94l78gc2g88cq3kbc0000gn/T/flutter_tools.MW6UxN/flutter_ios_build_temp_dirktvpW1/temporary_xcresult_bundle
/Applications/flutter/packages/flutter/lib/src/widgets/ticker_provider.dart:186:7: Error: 'ethrow' isn't a type.
ethrow FlutterError.fromParts(<DiagnosticsNode>[
^^^^^^
/Applications/flutter/packages/flutter/lib/src/widgets/ticker_provider.dart:186:14: Error: Expected ';' after this.
ethrow FlutterError.fromParts(<DiagnosticsNode>[
^^^^^^^^^^^^
/Applications/flutter/packages/flutter/lib/src/widgets/ticker_provider.dart:186:26: Error: Expected an identifier, but got '.'.
Try inserting an identifier before '.'.
ethrow FlutterError.fromParts(<DiagnosticsNode>[
^
/Applications/flutter/packages/flutter/lib/src/widgets/ticker_provider.dart:195:6: Error: A value of type 'bool?' can't be assigned to a variable of type 'bool' because 'bool?' is nullable and 'bool' isn't.
}());
^
Failed to package /Users/stankoo003/minimal_design.
Command PhaseScriptExecution failed with a nonzero exit code
note: Building targets in dependency order
warning: Run script build phase 'Thin Binary' will be run during every build because it does not specify any outputs. To address this warning, either add output dependencies to the script phase, or configure it to run in every build by unchecking "Based on dependency analysis" in the script phase. (in target 'Runner' from project 'Runner')
warning: Run script build phase 'Run Script' will be run during every build because it does not specify any outputs. To address this warning, either add output dependencies to the script phase, or configure it to run in every build by unchecking "Based on dependency analysis" in the script phase. (in target 'Runner' from project 'Runner')
Result bundle written to path:
/var/folders/bm/_wgnp7b94l78gc2g88cq3kbc0000gn/T/flutter_tools.MW6UxN/flutter_ios_build_temp_dirktvpW1/temporary_xcresult_bundle
Could not build the application for the simulator.
Error launching application on iPhone 14 Pro Max.
Exited
flutter doctor, empty projects..
This shows a problem in Flutter's TickerProvider class.
It might be a version problem. Try flutter upgrade.
Clean your project flutter clean then flutter pub get and try building again.

Error while building titanium apks with 3.0.0.GA sdk using ant scripting

I am getting the following error while trying to make titanium build with 3.0.0.GA using ant scripting
[exec] [ERROR] Error(s) compiling generated Java code
[exec] [ERROR] D:\Workarea\experiment\teacher\digitallyTE\build\android\gen
\com\edurite\digiteacher\DigitallyteApplication.java:36: cannot find symbol [exec] symbol : class AssetCryptImpl [exec] location: class com.edurite.digiteacher.DigitallyteApplication [exec] KrollAssetHelper.setAssetCrypt(new AssetCryptImpl()) ; [exec] ^ [exec] Note: D:\Workarea\experiment\teacher\digitallyTE\build\android\gen\c om\edurite\digitallyTE\AssetCryptImpl.java uses unchecked or unsafe operations. [exec] Note: Recompile with -Xlint:unchecked for details. [exec] 1 error [exec]
BUILD FAILED D:\Workarea\experiment\teacher\build.xml:11: exec returned: 1
Quite a while ago that the question was asked. But I guess my findings could be interesting as a AssetCryptImpl.java:44: error: cannot find symbol error happened to me lastly. The AssetCryptImpl.java template is filled with some asset variables during the build (check ~/.titanium/mobilesdk/linux/6.1.0.GA/android/cli/commands/_build.js). This process depends at least on Linux on some system commands. Those commands failed with a Segmentation Fault during my builds. Thus the asset variables don't get rendered inside the AssetCryptImpl.java template and the Java compiler will complain about missing symbols.
Check your build output for a line like
[INFO] : Encrypting JavaScript files: /home/simon/.titanium/mobilesdk/linux/6.1.0.GA/android/titanium_prep.linux64 "com.example.id" "/home/simon/test/Asdf/build/android/assets" "alloy/CFG.js" "app.js" "alloy/backbone.js" "alloy/constants.js" "alloy/controllers/BaseController.js" "alloy/controllers/index.js" "alloy/styles/index.js" "alloy/sync/localStorage.js" "alloy/sync/properties.js" "alloy/sync/sql.js" "alloy/underscore.js" "alloy/widget.js" "alloy.js" "ti.cloud/ti.cloud.js" "_app_props_.json"
and try to run the included command.

Emma failed, How to debug android test cases running on emulator?

I am trying to get coverage report by running ant emma on my mavenized android project, everything else went smoothly, but i bumped into NullPointerException when running
ant emma debug install test.
output is:
test:
[echo] WARNING: Code Coverage is currently only supported on the emulator and rooted devices.
[echo] Running tests ...
[exec]
[exec] com.jayway.maven.plugins.android.generation2.samples.libraryprojects.mainapp.MainActivityTest:INSTRUMENTATION_RESULT: shortMsg=java.lang.NullPointerException
[exec] INSTRUMENTATION_RESULT: longMsg=java.lang.NullPointerException: Unable to start activity ComponentInfo{com.jayway.maven.plugins.android.generation2.samples.libraryprojects.mainapp/com.jayway.maven.plugins.android.generation2.samples.libraryprojects.mainapp.MainActivity}: java.lang.NullPointerException
[exec] INSTRUMENTATION_CODE: 0
[echo] Downloading coverage file into project directory...
[exec] remote object '/data/data/com.jayway.maven.plugins.android.generation2.samples.libraryprojects.mainapp/coverage.ec' does not exist
How can I debug this ? I would like to find out where the NPE happened.

Run "ant test" using android sdk tools v14

After upgrading to android sdk tools v14 and updating existing projects to last project structure, ant test fails with the error message:
test:
[echo] Running tests ...
[exec] Syntax error: Bad substitution`
Output of ant -v test
[echo] Running tests ...
[exec] Current OS is Mac OS X
[exec] Executing '/opt/local/share/java/android-sdk-mac_x86/platform-tools/adb' with arguments:
[exec] 'shell'
[exec] 'am'
[exec] 'instrument'
[exec] '-w'
[exec] '-e'
[exec] 'coverage'
[exec] 'false'
[exec] 'xxx.xxx/xxx.xxx'
[exec]
[exec] The ' characters around the executable and arguments are
[exec] not part of the command.
But directly execute command adb shell am instrument is fine.
My environment is Apache Ant(TM) version 1.8.2 on Mac.
Please help.
It is a known issue of r14 tools. See http://tools.android.com/knownissues
Testing
ant test fails with Syntax error: Bad substitution.
A last minute change introduced this error in the Ant rules file. The workaround is to edit /tools/ant/build.xml, line 318 and to change ${manifest.package} with ${tested.manifest.package}. [Issue 20979]

Running android unit tests from the command line?

I'm trying to run unit tests on the android platform in accordance with tutorial. Say, for example, I want to run tests for Email application. I open /apps/Email/tests/AndroidManifest.xml file, look for the <manifest> element, and look at the package attribute, which is com.android.email.tests, and in the <instrumentation> element I look at the android:name attribute, which is android.test.InstrumentationTestRunner. Now I open the console, and run
$ . build/envsetup.sh
$ lunch 1
$ adb shell am instrument -w com.android.email.tests/android.test.InstrumentationTestRunner
But that fails:
INSTRUMENTATION_STATUS: id=ActivityManagerService
android.util.AndroidException: INSTRUMENTATION_FAILED: com.android.email.tests/android.test.InstrumentationTestRunner
INSTRUMENTATION_STATUS: Error=Unable to find instrumentation info for: ComponentInfo{com.android.email.tests/android.test.InstrumentationTestRunner}
So.. What am I doing wrong?
Please run
python development/testrunner/runtest.py email
and then you will see it works :).
Basically you do not have com.android.email.tests package installed.
You can see what is available for instrumentation
pm list instrumentation
And you should see
instrumentation:com.android.email.tests/android.test.InstrumentationTestRunner
(target=com.android.email)
And when doing
pm list packages
package:com.android.email
package:com.android.email.tests
You may need to setup a test project with the android create test-project command first. Check this page on the Android Dev site: Testing In Other IDE's for more info. I've used this method to enable command line testing with ant.
What I actually forgot to do was building and installing that test packages onto my device/emulator. Discovered that after doing:
$ adb shell
# cd data/packages
# ls
And no com.android.email.tests package there.
My issue was this tag:
<instrumentation
android:name="android.test.InstrumentationTestRunner"
android:label="Tests for app.under.test.package"
android:targetPackage="app.under.test.package" />
Firstly I had the android:name attribute wrong then the target package wrong (above is the correct solution)
Test Package Not Installed on the Emulator
I had the exact same issue and realized that the test package hadn't been installed on the emulator, which is what #marekdef is saying.
Instead of using the command found in the generated test file, I used the following:
ant debug install test
*I had my test project in <project_home>/tests so the following command is what I ended up using from my project home directory:
(cd tests && ant debug install test;)
Hope that helps.
I received the "Unable to find instrumentation info" error under this condition: I defined my test project with a src package name that was the same as that of the project-under-test. For example, the source for both projects was in package com.mycompany.android. This parallel-src-package setup worked fine in Eclipse, but on the emulator it very much appeared that the test apk was overwriting the app apk.
Fix: I changed the src packge of the test project to test.mycompany.android.
Note that, in either case, the Android manifest for the test project defines:
< manifest package="pkg-of-project-under-test" ...>
and
< instrumentation android:targetPackage="pkg-of-project-under-test" ...>
For gradle user you can use the following tasks:
$ gradle :project:installDebug :project:installDebugAndroidTest
I have this run_all_test.sh script to run all unit and instrumented test:
#!/bin/bash
./gradlew --no-daemon clean test connectedCheck --stacktrace;
if [ $? -eq 0 ]
then
echo "tests are successful"
else
echo "tests FAILED"
exit 1
fi
Explanation:
test -> execute all unit test
connectedCheck -> execute all instrumented test
You can start from here to customize it based on your needs following the documentation here: https://developer.android.com/studio/test/command-line
[Android test types]
To run all tests from Command Line using gradlew[About]
JUnit test (UnitTest suffix)
./gradlew test
./gradlew :<moduleName>:test<variantName>UnitTest
Instrument test(AndroidTest suffix)
./gradlew connectedAndroidTest
./gradlew :<moduleName>:connected<variantName>AndroidTest
If you want just to build tests and don't run them use assemble
//Unit
./gradlew :<moduleName>:assemble<variantName>UnitTest
//functional
./gradlew :<moduleName>:assemble<variantName>AndroidTest

Categories

Resources