amtrack / force-dev-tool

[DEPRECATED] Command line tool supporting the Force.com development lifecycle
MIT License
108 stars 37 forks source link

Addition of RunSpecifiedTests support #76

Closed extremesurfer closed 7 years ago

extremesurfer commented 7 years ago

Suggested new feature which we will fork/add and pull request if acceptable.

With large deployments into development environments where test execution can take several hours it is common practice to execute only the tests in the changeset and not the full suite.

It would be beneficial to have capability within the force-dev-tool to support this usecase.

Suggest:

New cli option deployRunSpecifiedTests added to force-dev-tool Usage: force-dev-tool deployRunSpecifiedTests [options] [tests] []

Tests: a list of test classes space separated OR use options -m

Options: -d= Directory containing the metadata and package.xml. -m=filemask Filemasks of the naming convention in the package.xml that identifies test classes e.g Test Mock -f= Zip file containing the metadata and package.xml.

Filemasks could be consistent with the test run config e.g inside quotes space separated expressions.

So you'd either supply the test classes on the cli, or provide a mask which looks at the classes in the package.xml and matches against the mask, then runs those. This will allow changeset development to only execute the tests in that changeset.

amtrack commented 7 years ago

Hi @extremesurfer, thank you for your feedback. I think this is a good idea.

Ideally we should add all of the DeployOptions from https://developer.salesforce.com/docs/atlas.en-us.api_meta.meta/api_meta/meta_deploy.htm as command line flags in a single sub command deploy and get rid of the deployTest, validate and validateTest sub commands.

  1. For the beginning, i suggest to modify lib/cli/deployTest.js to accept a --runTests argument. Accordingly, test classes could be specified by e.g. --runTests TestA TestB (or as one argument inside quotes as you mentioned). In the case --runTests is not empty, we would have to set testLevel from RunLocalTests to RunSpecifiedTests and add the runTests array to the deployOpts object.

You could then already run

$ force-dev-tool changeset create foo ApexClass/Foo ApexClass/TestFoo ApexClass/MockFoo
$ force-dev-tool deployTest -d config/deployments/foo --runTests TestFoo MockFoo
  1. Further i suggest adding a new sub command (eg. resolve, match or package grep...) that simply resolves patterns against the current package.xml (or org fetch result config/dev-fetch-result.json).
$ force-dev-tool package grep 'ApexClass/Test*' 'ApexClass/Mock*'
ApexClass/TestFoo
ApexClass/MockFoo

You could then combine those commands the unix way to s.th. like this:

$ force-dev-tool changeset create foo ApexClass/Foo ApexClass/TestFoo
$ force-dev-tool package grep 'ApexClass/Test*' 'ApexClass/Mock*' \
 | cut -d '/' -f 2 \
 | xargs force-dev-tool deployTest -d config/deployments/foo --runTests

Does that sound good to you? If you want to start with 1., i could also try to implement 2.

extremesurfer commented 7 years ago

Hi, yes that sounds good. We will do 1) hopefully by the end of this week.

amtrack commented 7 years ago

Hi @extremesurfer, FYI: I started working on 2) in #77.

mbertram commented 7 years ago

Hi @amtrack,

I started working on this ticket. It seems like you implemented it in 61b37e2 and already moved the code from the deployTest into the deploy command. Thanks for that. Is there anything left for this ticket we could help with?

amtrack commented 7 years ago

Hi @mbertram,

yeah, actually i just wanted to add support for the purgeOnDelete option and then i gave this a try as well :-).

I would appreciate if you could checkout the deploy branch to test this and see if this would fit your needs. Please see the examples from force-dev-tool help deploy (especially regarding xargs -0). I'll update the README.md when this will be merged.

amtrack commented 7 years ago

Released in v0.13.0