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

Ability to Run Specified Tests while comparing branches #140

Closed
ravaliyerrabelly opened this issue May 21, 2021 · 9 comments
Closed

Ability to Run Specified Tests while comparing branches #140

ravaliyerrabelly opened this issue May 21, 2021 · 9 comments
Assignees
Labels
enhancement New feature or request

Comments

@ravaliyerrabelly
Copy link

Is your proposal related to a problem?

Currently when diff one branch to another, we need the ability to automatically recognize test classes which are added as part of the diff to package.xml.

Describe the solution you'd like

When doing a diff from feature branch to DEV branch, if we could recognize test classes which have been changed and just
run those test classes it will save a lot of time rather than running all test classes

@ravaliyerrabelly ravaliyerrabelly added the enhancement New feature or request label May 21, 2021
@scolladon
Copy link
Owner

Hi @ravaliyerrabelly!

Thanks for your interest on making this plugin better!

This topic has already been discussed in another issue.
We came up with a solution using yq to show all the apex class listed in the package.xml.

You could reuse this approach and add a filter on the yq command to extract the apex class containing tests following your naming convention:
... select(.name=="ApexClass") | <filter members here> | .members | join(",")'

I hope it helps

@ravaliyerrabelly
Copy link
Author

ravaliyerrabelly commented May 25, 2021 via email

@scolladon
Copy link
Owner

Yes of course:

xq . < package/package.xml | jq '.Package.types | if type=="array" then .[] else . end | select(.name=="ApexClass") | <filter members here> | .members | join(",")'

@scolladon
Copy link
Owner

scolladon commented Feb 2, 2022

We close this issue as this is covered in the README

@rpawar655
Copy link

Can you please let me now the entire command which we have to use at the time for run :
sfdx force:source:deploy ...?
@scolladon
i want to validate the syntax to generate the delta test class and run ...

@scolladon
Copy link
Owner

Hi @rpawar655 !

Not sure to understand what you want.
Either the sfdx deploy command ?
Or the list of the test class to add to the deploy command, based on the content of the package.xml, and how to pass them to the deploy command ?

@rpawar655
Copy link

Hi @scolladon ,
I am looking for how i can pass to sfdx force:source:deploy cmd. It would be great if you suggest with one testclass example.

@scolladon
Copy link
Owner

Okay,

So, let's imagine we have this package.xml

<?xml version="1.0" encoding="UTF-8"?>
<Package xmlns="http://soap.sforce.com/2006/04/metadata">
    <types>
        <members>Service</members>
        <members>ServiceTest</members>
        <name>ApexClass</name>
    </types>
    <version>55.0</version>
</Package>

The file contains a ServiceTest member.
All the test class contains Test at the end of their name.
Then this xq | jq query will list all test class and separate them by ",":

$ xq . < output/package/package.xml | jq '.Package.types | [.] | flatten | map(select(.name=="ApexClass")) | .[] | .members | [.] | flatten | `map(select(. | index("*") | not)) | unique | map(select(. | index("Test")))  | join(",")'
> "ServiceTest"

Then I use it in the command line directly (I use zsh, it may be different based on your shell):

$ sfdx force:source:deploy --testlevel RunSpecifiedTests --runtests $(xq . < output/package/package.xml | jq '.Package.types | [.] | flatten | map(select(.name=="ApexClass")) | .[] | .members | [.] | flatten | map(select(. | index("*") | not)) | unique | map(select(. | index("Test")))  | join(",")')

You may want to extract it in a variable before (it may be different based on your shell):

$ SPECIFIED_TEST=$(xq . < output/package/package.xml | jq '.Package.types | [.] | flatten | map(select(.name=="ApexClass")) | .[] | .members | [.] | flatten | map(select(. | index("*") | not)) | unique | map(select(. | index("Test")))  | join(",")')
$ sfdx force:source:deploy --testlevel RunSpecifiedTests --runtests ${SPECIFIED_TEST}

I hope it helps!

@rpawar655
Copy link

Hey @scolladon That is what i am looking for thanks a ton 👍
Let me try out this in my CI/CD

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

No branches or pull requests

3 participants