Android Unit test are giving wrong result - android

When I run a unit test for a new created project then it shows me the wrong result (Says All Tests are passed).
If you see in the image below 4 is expected while 6+2 surely not 4.
Now when I run the same test from Gradle right menu. It shows me the correct result that test has failed.
Did I do anything wrong or is this an android studio bug?
Edit
Run configuration image

You need to add -ea option in the "VM options" box in your 3rd image. This is to enable assertion feature for the JVM. Without this -ea, JVM just ignore assertion statement.
When you run the test with gradle, it used a default configuration so that's why your test was run correctly.

Related

Re-run failed android tests

Is there a way to run only the failed set of tests on Android using Gradle?
At the moment, I run my tests as follows.
./gradle connectedDebugAndroidTest
There are tests that occasionally fail due to environment issues which are difficult to control and what I would like to do is be able to only run those failed tests and merge the result with the previous test results.
So for example, if I have 100 tests and 90 succeed, I would like to re-run the failing 10 tests. If those 10 pass the second time around, I would like to merge those results with the original test run.
It looks like this has been discussed several times for Gradle but there doesn't seem to be a solution yet.
https://github.com/gradle/gradle/issues/4068
https://github.com/gradle/gradle/issues/4450
https://github.com/gradle/gradle/issues/1283
Thanks!
The reason they don't have a way to only rerun failed tests is because it screws up the way Gradle currently works. This happens because on the first run, Gradle knows 90 tests passed. If you update the code, and then rerun only the 10 failed tests (using this new option you want them to add), then Gradle would think that all the tests have passed. However, this isn't the case because the tests which previously passed might've broken from the update which fixed the failing tests.
Despite this, the problem has been solved. Gradle reruns failed tests first, and provides a --fail-fast flag for the test task. This effectively does what you want (i.e., only reruns failed tests).
If you want to automatically rerun failed tests as part of the same build in which they failed, and succeed the build if they succeed on retry, you can use the Test Retry Gradle plugin. This will rerun each failed test a certain number of times, with the option of failing the build if too many failures have occurred overall.
plugins {
id 'org.gradle.test-retry' version '1.2.0'
}
test {
retry {
maxRetries = 3
maxFailures = 20 // Optional attribute
}
}

Google Test: Android vs Linux EXPECT_DEATH Tests

I am running into a problem while working on unit testing my system that I don't even know how to approach debugging. My code operates either on a linux machine with mock input or on an android device. I am using Google Test to run unit tests on it. I have it set up so that a call to "$ make all" will run my unit tests on both the linux machine and through adb shell on my device. This part is working fine.
However, when I introduce a test with EXPECT_DEATH(...) in it, the linux build runs the same as usual but the android build stops at that test and appears to freeze (I have to Ctrl + C to stop execution). As I said, I'm not at all sure how to try to fix this problem as I can't seem to get any output or error messages from it.
If you have any suggestions please let me know. If there is critical information I'm leaving out about my build, comment and I can add that in.
Edit:
When I run the function that I'm expecting to die outside of EXPECT_DEATH the same behavior occurs. This indicates that the assert in the function is working and EXPECT_DEATH is not doing what it should to handle that.
Before: (Works fine on Linux build but not on Android build)
EXPECT_DEATH(pObj->fxn(deathlyParam), "");
After: (Same result on Android build; core dump error due to assert on Linux build which is what I would expect both times from the Android build)
EXPECT_EQ(pObj->fxn(deathlyParam), 0);
For reference, fxn() looks something like this:
int fxn(int param)
{
assert(param != deathlyParam);
...
}
In light of this, it looks more like assert is acting improperly and not causing the error it should be. Therefore, EXPECT_DEATH has nothing to expect.
OK I figured it out. The problem was indeed arising from the assert in my function and not from EXPECT_DEATH. I don't know if this is just a feature of the project I'm working on (which had been developed for some time before I got to it) or if it is true of any Android build but NDEBUG was undefined, as in a release build. When I added "APP_OPTIM := debug" to my Application.mk file, it worked perfectly.
I am still a little confused why an assert would seemingly halt execution when NDEBUG is undefined. Aren't asserts supposed to be ignored entirely in release builds?
Credit to this question and answer for the solution.

PaClient error: E0002 Missing profile name

I try to make an android application in delphi but when i build the project i get this error:
[PAClient Error] Error: E0002 Missing profile name; use paclient -?
for Help
How can i fix this?
You may check your configuration as well in Delphi XE 8.1:
Build Configuration: RELEASE
Android: APPLICATION STORE
For instance DEBUG and APPLICATION STORE may result in a E00002 error.
For building Android applications in delphi, you do not use the PAServer nor PAClient, so there is no profile: these are only needed for iOS or OS X development.
To figure out what is calling PAClient and why the call fails, follow these steps:
Run Delphi while the free Process Monitor from SysInternals is active,
watch the Process Monitor log to see when the PAClient is executed, and what parameters there are.
Relate these parameters to the selected profile
Note that error E00002 means the PAClient has no profile name in the parameters.
Also check Project -> Deployment that all items are checked. That worked for me.
(I unchecked all items by mistake when adding some files for deployment manually)
Via FFernandes https://forums.embarcadero.com/thread.jspa?threadID=118789

infinitest usage with Robotium for Android

I cant get infinitest(continuous test runner for TDD) to auto test with android junit test cases. Im using Robotium for UI testing.
Is infinitest compatible with Robotium ?
Here is the Problem page error (within eclipse Problem window) i get even though my test cases run fine when executed manually:
Description Resource Path Location Type
RuntimeException (Stub!) in ProjectTests. ProjectTests.java
line 0 Infinitest Test Failure

Error while trying to apportable iOS app to Android

I have been trying to port my first iOS app to Android with apportable.
I have solved alot of warnings and errors but cannot get rid of this last one.
The App I made is a fitness application for jogging so it uses CoreLocation.
Everything looks good when I run apportable now except this last error:
Build/android-armeabi-debug/com.apptonix.easyrunner/testTabbedWithCore/libtestTabbedWithCore.a(DetailViewController.m.o):/Users/peterbodlund/Documents/xcodeprojects/Training/inlamning5/testTabbedWithCore/testTabbedWithCore/DetailViewController.m:function L_OBJC_CLASSLIST_REFERENCES_$_114: error: undefined reference to 'OBJC_CLASS_$_MKPinAnnotationView'
scons: * [Build/android-armeabi-debug/EasyRunner/apk/lib/armeabi/libverde.so] Error 1
scons: building terminated because of errors.
Exception AttributeError: "'NoneType' object has no attribute 'pack'" in > ignored
Usually this is an indicator that there were link errors. Check your output higher up and look for missing symbol errors.
The build log is confusing because the build is parallel by default.
Add the option -j1 to cause the build to stop immediately after the first error.

Categories

Resources