Skip to content

MFTF test packaging proposal #172

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

Merged
merged 8 commits into from
Jul 22, 2019

Conversation

okolesnyk
Copy link
Member

@okolesnyk okolesnyk commented May 29, 2019

Problem

Tests are dead code on production env.

Solution

Exclude tests from magento2-module package and introduce new type of packages with Tests only
There is going to be new modules which will have Functional Tests only.
Example:
CatalogAdminUi - will have Magento Admin UI logic inside
CatalogAdminUiFunctionalTest - will have Automated Test Coverage for Catalog Magento Admin UI module

Requested Reviewers

@paliarush
@maghamed
@buskamuza
@antonkril

@vkublytskyi
Copy link

For sure, code that may be executed is a subject of attack but in case of MFTF module contains only XML configuration so no executable that may be used somehow while MFTF itself is not installed.

Another question that deserves explicit discussion is what is the production environment for Magento. I totally agree that running instance of Magento that serve real merchant customers should not contain any executable test code. But are composer packages that we produce production code or not? With removing our tests from packages we increase the complexity of system integrators and vendors workflow and internal and external CI infrastructures. It also leads to controversial decisions in release management and packaging.

Alternatively, we may consider a possibility to provide instruments to remove test code (including from any possible 3rd party extensions and SI customizations) as part of operations during deploying Magento. This may be done as CLI command which may be part of enabling the production mode. Or it may be done by Composer plugin that will remove test code if --no-dev flag is used for composer install or composer update commands. In addition, we may detect available test code and show a warning message in the admin panel to clearly communicate potential security issue and need to perform actions on the server side.

 - update directory
@okolesnyk okolesnyk force-pushed the tests-packaging-new branch from 1629b01 to d4cefd7 Compare June 6, 2019 19:17
 - address comment
@melnikovi melnikovi self-assigned this Jun 11, 2019
@okolesnyk
Copy link
Member Author

@melnikovi Yes, I will investigate tooling for that. Will update document afterwards.

@buskamuza buskamuza self-requested a review June 13, 2019 22:23
2. Create `magento2-module` package as usual, but without tests.

3. Out of excluded tests create a separate package.
- For this package we will automatically generate `composer.json` based on existing module `composer.json` file as shown on image below.
Copy link
Contributor

Choose a reason for hiding this comment

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

type: "magento2-test-module" - will this information be used anywhere or can we use just standard Composer type library?

 - Update proposal to match [Module separation naming]
 - Update proposal to match [Module separation naming]

#### Magento metapackage
In Magento `magento/project-community-edition` we will be able to specify 2 metapackage under different blocks.
Magento application will go to `require` section as it is right now and we will be able to put `magento/functional-test-project-community-edition` under `require-dev` section.

Choose a reason for hiding this comment

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

functional-tests (instead of test?)

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes. This proposal is about packaging Functional tests only. And they shouldn't be distributed with other test types together.

Copy link
Contributor

@ravmenon ravmenon left a comment

Choose a reason for hiding this comment

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

Overall, I am in favor of this proposal. It aligns well with the the best practices mentioned here: https://sormuras.github.io/blog/2018-09-11-testing-in-the-modular-world.html

@okolesnyk
Copy link
Member Author

@ravmenon Please take a look at files section and you will see that proposal was changed drastically. So some of your comments goes to outdated part.


#### Magento metapackage
In Magento `magento/project-community-edition` we will be able to specify 2 metapackage under different blocks.
Magento application will go to `require` section as it is right now and we will be able to put `magento/functional-test-project-community-edition` under `require-dev` section.
Copy link
Contributor

@buskamuza buskamuza Jun 20, 2019

Choose a reason for hiding this comment

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

It looks odd to include project in a project. Maybe this metapackage should not be called project? And someone can include it in the "Magento project" or to create an empty "project" for tests and include this metapackage. Could you please also include more details what do you expect in the metapackage? Does it include all the frameworks?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, that is typo. It meant to be magento/functional-test-product-community-edition

Copy link
Contributor

@buskamuza buskamuza left a comment

Choose a reason for hiding this comment

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

Also, documentation should explicitly state that Web Setup Wizard does not support testing packages and it's intentional (because it's considered to be used in production). Please confirm with PO and validate that this is real behavior (when implementing).

>Future-proof:
> - ability to release separately, on separate cadence
> - matches the general plan for all other non-critical modules - we want to modularize and release separately things like payment extensions, shipping and more.

Copy link
Contributor

Choose a reason for hiding this comment

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

Performance:

  • MFTF coverage grows drastically, which side effect is growing deployment time for staging / production environment

@lbajsarowicz
Copy link
Contributor

I'm not sure if I'm missing something, but...
I'd take another approach. Each module having it's FunctionalTest dependency in it's composer.json as a -dev requirement. So that doint composer install --no-dev just does not install the tests.

In practice - each module needs tests only for dev environment, so this dependency would be reasonable.

@okolesnyk
Copy link
Member Author

okolesnyk commented Jun 26, 2019

Adding here discussion from Slack channel to not loose it.

Kristof Ringleff, Fooman [Jun 20th at 6:50 PM]
@okolesnyk thanks for sharing. My immediate thoughts are:

  1. the functional test metapackage should not live in the require-dev section of
    magento/project-community-edition
    but rather in the require-dev section of magento/product-community-edition

I believe the sooner Magento understands that magento/project-community-edition is merely a suggested starting template for a project the better. (it's like using eject on a node package, from there you are on your own and Magento no longer is able to easily update it).

  1. Looking at my own tests so far I am not sure if
    CatalogAdminUiFunctionalTest
    is too granular. Usually with my acceptance tests I need to configure something, checkout, look again in the admin. I believe a lot of tests would be like that (otherwise it could be more easily covered with other types of tests). So if I were to split the actual tests into multiple packages I end up with nothing that actually tests meaningful up until I combine them all again anyway. In which case it would be easier to just have CatalogFunctionalTest. But maybe for now if this is proposal is for Magento Core only and extension devs can decide to follow the split or keep them in one that would work for me.
    (I guess I am generally not quite sure how the service isolation is going to work with tests)

  2. There is a similar challenge around integration tests. Any thoughts on how these would work alongside this proposal?
    4 replies

Alex Kolesnyk [1 day ago]
Hi @fooman

  1. Agree with you. I think we should add all test packages in the require-dev block of magento/product-community-edition.
    But the thing is that we will have a possibility to install Magento without tests and I wanted to have possibility to do the same with tests.
    Let’s imagine you have Magento Instance somewhere out of local env and you what to run and write Functional tests only. Yes, you can composer install same package but you will have unnecessary Magento application code.
    What do you think if we also will generate magento/functional-tests-community-edition metapackage which will include under require only test packages ? (edited)

  2. That’s a good point. The idea why I invented :rolling_on_the_floor_laughing: this naming convention {ModuleName}FunctionalTest is very simple. Currently before generating all tests MFTF makes request to Magento WebAPI asking a list of enabled modules and component load order. This gives MFTF a possibility to generate only tests for enabled modules and using load order we know in what order we should merge all XML entities.
    If we will make possible to create a Single Test Module for some group of Magento modules we need to figure out how to specify in TestModule what Modules must be enabled in Magento. For this I created an issue under MFTF repo where you can put your thoughts [Discussion] MFTF tests in separate Magento modules magento2-functional-testing-framework#373
    GitHub
    [Discussion] MFTF tests in separate Magento modules · Issue Integration test data fixture change proposal #373 · magento/magento2-functional-testing-framework
    Goals Discuss changes related to MFTF test packaging proposal #172 Build backlog to support proposed Module structure for MFTF tests

  3. No, we don’t have it for Integration tests yet, but out of this proposal right after we approve it I think it will be much easier to build something similar for Integration tests and maybe for all other test types.

 - small changes to address comments

#### Magento metapackage
In Magento `magento/project-community-edition` we will be able to specify 2 metapackage under different blocks.
Magento application will go to `require` section as it is right now and we will be able to put `magento/functional-test-project-community-edition` under `require-dev` section.
Copy link

@xmav xmav Jun 26, 2019

Choose a reason for hiding this comment

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

We might want to move "magento/magento2-functional-testing-framework" from 'require-dev' to new meta package with tests as well

Edited:
In order to support existing mftf tests in 3rd party modules we should keep it

@buskamuza
Copy link
Contributor

@lbajsarowicz, dev dependencies are supported in the root composer.json only.

@buskamuza
Copy link
Contributor

buskamuza commented Jun 27, 2019

the functional test metapackage should not live in the require-dev section of
magento/project-community-edition
but rather in the require-dev section of magento/product-community-edition

Same. It will not work. require-dev is supported on the project level only.

 - small changes to address comments from arch meeting
@okolesnyk
Copy link
Member Author

@buskamuza @melnikovi @paliarush @maghamed Do I need to do something with this proposal? Or we can merge it and I will proceed with implementation tasks and implementation itself?

@melnikovi melnikovi self-requested a review July 22, 2019 15:19
@melnikovi melnikovi merged commit 33059df into magento:master Jul 22, 2019
@fooman
Copy link

fooman commented Aug 30, 2019

@buskamuza sorry missed this discussion and your comment. Keeping the testing metapackage out of the root composer.json require-dev section was exactly my point. If someone chooses to use the same tools as Magento for their development - great. It's only a
composer require --dev magento/functional-metapackage away.

@buskamuza
Copy link
Contributor

buskamuza commented Sep 3, 2019

magento/project-community-edition is merely a suggested starting template for a project

Exactly. So we're adding the testing metapacakge to reqiuire-dev section of the suggested project template. If somebody doesn't want to use it, they can modify the composer.json. As soon as the project owner creates the project, composer.json is not under Magento's control anymore.
But it's a good place to show what exists natively.
In any case, I was just noticing that we can't use require-dev section in the "product" metapackage because it will not work. From there, we can either include or exclude tests from the project.

@fooman
Copy link

fooman commented Sep 6, 2019

@buskamuza I was hoping that this proposal here #157 was going ahead.

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.

10 participants