Open nc-jeni opened 7 months ago
Hi @nc-jeni. Sorry for the late reply. I'm glad that you managed to fix your issue. I see two action points based on what you've written:
MainActivity.kt
.
So let's use this issue to track the second one.Makes it more clear in docs how to setup the patrol in project when main android file is MainActivity.kt. So let's use this issue to track the second one.
Does this require additional change?
Steps to reproduce
I am unable to find the output of the tests. After I have ran the tests, it just says the tests have been executed successfully regardless of the results of the individual tests even that I know that some have failed and expect to see something like this.
I just started the test by
patrol test
orpatrol test --flavor development
and waited for the the result of the test such asHere goes my
MainActivityTest
class placed in\android\app\src\androidTest\kotlin\<applicationId>
while theMainActivity
class is placed in\android\app\src\main\kotlin\<applicationId>
. Both of the classes are Kotlin. Secondly, I am unable to use a Java implementation of theMainActivityTest
class as provided in your sample app hence it cannot find the Kotlin implementation of theMainActivity
class.I am expecting one or more of the following output options
It is also related to: https://github.com/leancodepl/patrol/issues/2066, https://github.com/flutter/flutter/issues/62237, https://github.com/leancodepl/patrol/issues/1170
Note: I am not sure whether it is because it does not produce any output, or because no tests are found even tests actually exists.
Actual results
Patrol Test Output
``` No device specified, using the first one (emulator-5554) • Building apk with entrypoint test_bundle.dart... ✓ Completed building apk with entrypoint test_bundle.dart (40.2s) • Executing tests of apk with entrypoint test_bundle.dart on emulator-5554... ✓ Completed executing apk with entrypoint test_bundle.dart on emulator-5554 (8.8s) ```Logs
LogCat
``` ----- begin exception ----- java.lang.RuntimeException: Unable to run tests due to missing activity rule at dev.flutter.plugins.integration_test.FlutterTestRunner.run(FlutterTestRunner.java:57) at org.junit.runners.Suite.runChild(Suite.java:128) at org.junit.runners.Suite.runChild(Suite.java:27) at org.junit.runners.ParentRunner$4.run(ParentRunner.java:331) at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:79) at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:329) at org.junit.runners.ParentRunner.access$100(ParentRunner.java:66) at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:293) at org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306) at org.junit.runners.ParentRunner.run(ParentRunner.java:413) at org.junit.runner.JUnitCore.run(JUnitCore.java:137) at org.junit.runner.JUnitCore.run(JUnitCore.java:115) at androidx.test.internal.runner.TestExecutor.execute(TestExecutor.java:67) at androidx.test.internal.runner.TestExecutor.execute(TestExecutor.java:58) at androidx.test.runner.AndroidJUnitRunner.onStart(AndroidJUnitRunner.java:446) at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:2402) ----- end exception ----- ```Patrol version
Patrol Doctor output
Patrol Doctor output
``` Patrol doctor: Patrol CLI version: 2.6.1 Android: • Program adb found in AppData\Local\Android\Sdk\platform-tools\adb.exe • Env var $ANDROID_HOME set to AppData\Local\Android\Sdk ```Flutter Doctor output
Flutter Doctor output
``` [√] Android toolchain - develop for Android devices (Android SDK version 33.0.2) [√] Chrome - develop for the web [!] Visual Studio - develop Windows apps (Visual Studio Build Tools 2022 17.6.2) X Visual Studio is missing necessary components. Please re-run the Visual Studio installer for the "Desktop development with C++" workload, and include these components: MSVC v142 - VS 2019 C++ x64/x86 build tools - If there are multiple build tool versions available, install the latest C++ CMake tools for Windows Windows 10 SDK [√] Android Studio (version 2022.2) [√] IntelliJ IDEA Community Edition (version 2022.3) [√] VS Code (version 1.77.3) [√] Connected device (4 available) [√] Network resources ```Please note that the issue from flutter doctor (see above) can be ignored hence I use Android Studio and not Visual Studio.
UPDATE
I tried to change the runner
Plus adding the dependencies
This gives the following error that boils down to stack trace with roots in Patrol
StackTrace from LogCat
``` ✗ Failed to execute tests of apk with entrypoint test_bundle.dart on emulator-5554 (Gradle test execution failed with code 1) (15.9s) Exception: Gradle test execution failed with code 1 #0 AndroidTestBackend.execute.The reason for changing the runner away from
PatrolJUnitRunner
was that it was unable to run tests due to missing activity rule.StackTrace when using PatrolJUnitRunner
``` ----- begin exception ----- java.lang.RuntimeException: Unable to run tests due to missing activity rule at dev.flutter.plugins.integration_test.FlutterTestRunner.run(FlutterTestRunner.java:57) at org.junit.runners.Suite.runChild(Suite.java:128) at org.junit.runners.Suite.runChild(Suite.java:27) at org.junit.runners.ParentRunner$4.run(ParentRunner.java:331) at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:79) at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:329) at org.junit.runners.ParentRunner.access$100(ParentRunner.java:66) at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:293) at org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306) at org.junit.runners.ParentRunner.run(ParentRunner.java:413) at org.junit.runner.JUnitCore.run(JUnitCore.java:137) at org.junit.runner.JUnitCore.run(JUnitCore.java:115) at androidx.test.internal.runner.TestExecutor.execute(TestExecutor.java:67) at androidx.test.internal.runner.TestExecutor.execute(TestExecutor.java:58) at androidx.test.runner.AndroidJUnitRunner.onStart(AndroidJUnitRunner.java:446) at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:2402) ----- end exception ----- ```Sticking to the
PatrolJUnitRunner
by using the Java version of theMainActivityTest
and porting theMainActivity
to Java gives the following StackTrace and hangs forever. However, the binding exception was solved by removingIntegrationTestWidgetsFlutterBinding.ensureInitialized();
in top of themain()
method in the integration test.StackTrace when MainActivity and MainActivityTest is Java and PatrolJUnitRunner is used
``` E [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: 'package:flutter/src/foundation/binding.dart': Failed assertion: line 153 pos 12: '_debugInitializedType == null': Binding is already initialized to PatrolBinding #0 _AssertionError._doThrowNew (dart:core-patch/errors_patch.dart:51:61) #1 _AssertionError._throwNew (dart:core-patch/errors_patch.dart:40:5) #2 new BindingBase (package:flutter/src/foundation/binding.dart:153:12) #3 new _TestWidgetsFlutterBinding&BindingBase&SchedulerBinding (package:flutter_test/src/binding.dart) #4 new _TestWidgetsFlutterBinding&BindingBase&SchedulerBinding&ServicesBinding (package:flutter_test/src/binding.dart) #5 new _TestWidgetsFlutterBinding&BindingBase&SchedulerBinding&ServicesBinding&GestureBinding (package:flutter_test/src/binding.dart) #6 new _TestWidgetsFlutterBinding&BindingBase&SchedulerBinding&ServicesBinding&GestureBinding&SemanticsBinding (package:flutter_test/src/binding.dart) #7 new _TestWidgetsFlutterBinding&BindingBase&SchedulerBinding&ServicesBinding&GestureBinding&SemanticsBinding&RendererBinding (package:flutter_test/src/binding.dart) #8 new _TestWidgetsFlutterBinding&BindingBase&SchedulerBinding&ServicesBinding&GestureBinding&SemanticsBinding&RendererBinding&PaintingBinding (package:flutter_test/src/binding.dart) #9 new _TestWidgetsFlutterBinding&BindingBase&SchedulerBinding&ServicesBinding&GestureBinding&SemanticsBinding&RendererBinding&PaintingBinding&WidgetsBinding (package:flutter_test/src/binding.dart) #10 new _TestWidgetsFlutterBinding&BindingBase&SchedulerBinding&ServicesBinding&GestureBinding&SemanticsBinding&RendererBinding&PaintingBinding&WidgetsBinding&TestDefaultBinaryMessengerBinding (package:flutter_test/src/binding.dart) #11 new TestWidgetsFlutterBinding (package:flutter_test/src/binding.dart) #12 new LiveTestWidgetsFlutterBinding (package:flutter_test/src/binding.dart) #13 new IntegrationTestWidgetsFlutterBinding (package:integration_test/integration_test.dart) #14 IntegrationTestWidgetsFlutterBinding.ensureInitialized (package:integration_test/integration_test.dart:154:7) #15 main (file:///.../integration_test/app_test.dart:48:40) #16 Declarer.group.SOLVED
MainActivityTest
in Java at android\app\src\androidTest\java\<applicationId>MainActivity
in Java at android\app\src\main\java\<applicationId>MainActivity
in Kotlin that is placed at android\app\src\main\kotlin\<applicationId>Kotlin approach does not compute!
dependencies
section in build.gradledefaultConfig
section in build.gradleAvoid calling
IntegrationTestWidgetsFlutterBinding.ensureInitialized();
in main()Find the result at build\app\reports\androidTests\connected\index.html as expected, but not in console when all tests pass. However, when failures it is shown with a link to the test overview, but when all tests are passed it will be appreciated if it is visible upfront that they have been found and executed with success.
Note: A better guide that more strictly describes how to setup, and clearly describes what does not work is appreciated. Especially, the Java vs. Kotlin approach as it is pretty confusing hence your sample app mixes those even that it does work. Feel free to use the steps I have outlined above for inspiration to an improved guide.