Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduced CucumberJUnitRunner - a bridge between Cucumber Features and Android Test Orchestrator #14

Merged

Conversation

lifedemons
Copy link
Contributor

This PR proposes the way of integration between Android Test Orchestrator(e.g. AndroidJUnitRunner) and Cucumber for Android.
Essentially:

  • Cucumber operates with PickleEvents - representation of tests
  • Android Test Orchestrator operates with Junit Tests/Runners

So, we map List of PickleEvents to List of JUnit Description via implementing of custom CucumberJUnitRunner

As result, this allows:

  • to shard tests on Cucumber
  • to use Spoon dynamic sharding with Cucumber - when Spoon detects all connected devices and distributes tests between them

@lifedemons lifedemons force-pushed the feature/2/android_orchestrator_integration branch from f7f347e to fcd70d3 Compare February 15, 2019 00:23
@Override
public void onCreate(final Bundle bundle) {
bundle.putString("plugin", getPluginConfigurationString()); // we programmatically create the plugin configuration
bundle.putString(ARGUMENT_ORCHESTRATOR_RUNNER_BUILDER, CucumberJUnitRunnerBuilder.class.getName());
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we need to pass CucumberJUnitRunnerBuilder to AndroidJUnitRunner so then it will automatically be asked to create CucumberJUnitRunner

}

/**
* Runs the cucumber scenarios with the specified arguments.
*/
public void execute() {
instrumentationReporter.setNumberOfTests(getNumberOfConcreteScenarios());
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we need to defer a moment of reporting of total tests to right before the execution, because then filtering of tests can be applied:
fcd70d3#diff-9d77d6e39a9caffbbd7c7854efbb2fe0R67

public CucumberJUnitRunner(Class testClass) {
instrumentationRunner = (CucumberAndroidJUnitRunner) InstrumentationRegistry
.getInstrumentation();
cucumberExecutor = new CucumberExecutor(new Arguments(instrumentationRunner.getArguments()),
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bundle arguments are stored in CucumberAndroidJUnitRunner for backward compatibility with Cucumbers tags/configuring

public class CucumberJUnitRunnerBuilder extends RunnerBuilder {
@Override
public Runner runnerForClass(final Class<?> testClass) {
if (testClass.equals(this.getClass())) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it is needed for this Builder to work only once - so we run it one Class from tests Classpath - for itself

@@ -96,6 +96,7 @@ spoon {
debug = true
singleInstrumentationCall = true
grantAll = true
shard = true
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dynamic Spoon sharding

@lifedemons
Copy link
Contributor Author

lifedemons commented Feb 15, 2019

it is strange, but the project doesn't compile for me on cucumber java 4.2.3-SNAPSHOT or 4.2.3 but compiles fine on 4.2.2

@mpkorstanje
Copy link
Contributor

There have been some internal API changes in 2.4.3. Glue and feature paths are now passed as URI's internally. This avoids having to deal with arbitrary user input everywhere.

@lsuski
Copy link
Contributor

lsuski commented Feb 17, 2019

I'll try to check this in next week

@lsuski
Copy link
Contributor

lsuski commented Feb 19, 2019

I'm currently making small refactoring in this PR: removing duplicates and migrating to androidx and this runner is not working, likely due to changes in androidx.test classes. I'll figure this out and push my changes in few days

@lsuski
Copy link
Contributor

lsuski commented Feb 20, 2019

This branch should compile now but it does not execute any tests (at least running from Android Studio). @lifedemons did you tested it? In my opinion it can't work here

 if (testClass.equals(getClass())) {
            return new CucumberJUnitRunner(testClass);
        }

because there is a filter which filters out classes not belonging to test package.

@lifedemons
Copy link
Contributor Author

@lsuski cukeulator example runs for me after your committed changes from Android Studio and from gradle command connectedAndroidTest:
androidstudio

@lifedemons
Copy link
Contributor Author

also if you execute spoonDebugAndroidTest then you should get parallel execution with a report:
spoon

@lifedemons
Copy link
Contributor Author

lifedemons commented Feb 20, 2019

in order to supply CucumberJUnitRunner I used CucumberJUnitRunnerBuilder inside CucumberAndroidJUnitRunner, so CucumberAndroidJUnitRunner should be defined as testInstrumentationRunner "cucumber.api.android.CucumberAndroidJUnitRunner".

So, this CucumberJUnitRunner instance is created only once per Features run and then it provides the full list of JUnit Descriptions in the function:

@Override
    public Description getDescription() {
        Description rootDescription = Description.createSuiteDescription("All tests", 1);

        for (PickleEvent pickleEvent : pickleEvents) {
            rootDescription.addChild(makeDescriptionFromPickle(pickleEvent));
        }
        return rootDescription;
    }

@lifedemons
Copy link
Contributor Author

so, please, let me know does clean cukeulator example run for you on the current latest commit

@lsuski
Copy link
Contributor

lsuski commented Feb 21, 2019

Yes, it works, I've run tests in AS for package and that's was the case. However did you tested it with Android Orchestrator (as PR title suggests) because current configuration does not use it.
Android Test Orchestrator != AndroidJunitRunner

@lsuski
Copy link
Contributor

lsuski commented Feb 21, 2019

I wasn't able to make it work with orchestrator, however it's not critical feature for me. Sharding is much more useful with large test base

…der from duplicated code, remove AndroidObjectFactory
@lifedemons
Copy link
Contributor Author

@lsuski I agree with you about importancy of sharding vs isolated running of all tests via Android Test Orchestrator, so this PR was intended to bring sharding.
But I will try today to make it compatible with the isolated/orchestrated running of all tests via Android Test Orchestrator.

@lifedemons
Copy link
Contributor Author

@lsuski thank you for your feedback 👍

@lifedemons
Copy link
Contributor Author

@lsuski I've made some progress in Android Test Orchestrators' isolated test Instrumentations:
lifedemons@6c328ef

What I see here:

  • Android Test Orchestrator(ATO) runs first time for gathering list of tests
  • Then ATO creates new Instrumentation for every test from the list and feeds "class" Bundle argument
  • The example of this Bundle Argument after test run of CucumberAndroidJUnitRunner is
    class 'features_operations_subtraction.feature#Enter two digits per number and press = 2'
  • we can't pass this Bundle Argument to AndroidJUnitRunner because it attempts to create an instance of this test Class, so the idea is to intercept it and filter on Cucumber side

what do you think?

@lsuski
Copy link
Contributor

lsuski commented Feb 22, 2019

Cucumber has its own filtering mechanism and I think we should use it instead. I'll try it today

@lsuski
Copy link
Contributor

lsuski commented Feb 22, 2019

I've made some enhancements and this should finally work. I'll push my changes here after weekend

@lsuski
Copy link
Contributor

lsuski commented Feb 26, 2019

Everything should work now. @lifedemons check this with your project

@lifedemons
Copy link
Contributor Author

@lsuski I've checked - works fine. great job 👍

@lsuski lsuski merged commit 15cbf8f into cucumber:master Feb 27, 2019
@aslakhellesoy
Copy link
Contributor

Hi @lifedemons,

Thanks for your making your first contribution to Cucumber, and welcome to the Cucumber committers team! You can now push directly to this repo and all other repos under the cucumber organization! 🍾

In return for this generous offer we hope you will:

  • ✅ Continue to use branches and pull requests. When someone on the core team approves a pull request (yours or someone else's), you're welcome to merge it yourself.
  • 💚 Commit to setting a good example by following and upholding our code of conduct in your interactions with other collaborators and users.
  • 💬 Join the community Slack channel to meet the rest of the team and make yourself at home.
  • ℹ️ Don't feel obliged to help, just do what you can if you have the time and the energy.
  • 🙋 Ask if you need anything. We're looking for feedback about how to make the project more welcoming, so please tell us!

On behalf of the Cucumber core team,
Aslak Hellesøy
Creator of Cucumber

@VikOles
Copy link

VikOles commented Mar 10, 2021

Hi, @lifedemons, @aslakhellesoy. I have an issue with implementation of cucumber with the orchestrator. Could you provide the setting which you use for it?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants