amtrack / force-dev-tool

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

Deploy and test a single file #40

Closed janraasch closed 8 years ago

janraasch commented 8 years ago

Hi @amtrack,

I tried out this tool and I must say I really like it. This probably will help us quiet a lot with streamlining our SF dev cycle. So thank you very much :)

One question I have is how to best deploy a single file and test it.

I could see myself wiring up a little build command into my editor, that on saving a file creates a changeset with just one file and deploys it to my sandbox of choice, but then how could I run just a single test.

Can you recommend a strategy or is there maybe a feature request (i.e. run single test files on a sandbox) hidden in this question?

Keep up the great work :)

janraasch commented 8 years ago

Update:

Started workin on an implementation to run test files on a remote: https://github.com/janraasch/force-dev-tool/tree/feature/run-tests

Comments welcome :)

Will probably open a pr, when finished...

Still I would very much appreciate your feedback on how to best implement the suggested workflow.

amtrack commented 8 years ago

Hi @janraasch

first off, thank you for your feedback and it makes me pretty happy to hear that you like it!

If i understand your use case correctly, you want to deploy your class together with your test class (e.g. src/classes/MyClass.cls, src/classes/Test_MyClass.cls) and then, as a second step, run the unit tests for the test class Test_MyClass.

Your approach implementing run_tests would then work like this:

$ force-dev-tool changeset create foo src/classes/MyClass.cls src/classes/Test_MyClass.cls -f
$ force-dev-tool deploy -d config/deployments/foo mydev2
$ force-dev-tool run_tests Test_MyClass mydev2

To make this more generic, i suggest s.th. like the following solution:

Background:

The commands deployTest, validate, validateTest and test currently just act as an alias for deploy with certain arguments. The test command at the moment is implemented to perform an empty deployment with the option to run all tests.

Adjust the existing lib/cli/deploy.js command accepting the following args

The arguments would be identical to the DeployOptions of the metadata deploy() call.

Extend the test command (and maybe others) to accept the --runTests argument as well.

This would allow you to deploy and test in two separate steps

$ force-dev-tool changeset create foo src/classes/MyClass.cls src/classes/Test_MyClass.cls -f
$ force-dev-tool deploy -d config/deployments/foo mydev2
$ force-dev-tool test --runTests Test_MyClass mydev2

or in a single step (e.g. rejecting the deployment if the test fails)

$ force-dev-tool changeset create foo src/classes/MyClass.cls src/classes/Test_MyClass.cls -f
$ force-dev-tool deploy -d config/deployments/foo --runTests MyClassTest mydev2

Does that make sense to you?

If you like, we could also have a chat or hangout using Google Hangouts.

janraasch commented 8 years ago

Thank you for your detailed response.

First I should explain a little more in-depth what (I think :)) I would want to do.

You got this almost correct when saying that

you want to deploy your class together with your test class (e.g. src/classes/MyClass.cls, src/classes/Test_MyClass.cls) and then, as a second step, run the unit tests for the test class Test_MyClass.

but my idea is broader.

In a typical day-to-day workflow, I as a SF developer want to do two things quiet a lot:

What you described would work, when I always want to do the two tasks together, but that is a constraint I do not want to impose. Here's why: Maybe I am just writing some code and I want to try things out on the UI or by executing a script. I might not have test cases for the functionality or my feature might even break some tests, but still I would like to deploy the code to actually see it in action.

In the end, once I can do these to tasks Upload a file to my sandbox and Run a test case via the command line (as I can with the code on https://github.com/janraasch/force-dev-tool/tree/feature/run-tests) I can now integrate this into any editor (e.g. Sublime, Atom, vim,...). E.g. when saving a file I could directly upload the file to my sandbox. And when I am editing a Test_* file I could have a context menu entry, where I can say Run test on sandbox.

Basically this all is mimicking some of the functionality of the Force.com IDE and the Web Console, but for not being tied to a specific IDE, since the commands exist on the command line.

What do you think? Is this making sense?

amtrack commented 8 years ago

Let's talk about this on friday in detail!

janraasch commented 8 years ago

Thanks again for takin' the time to have a call. So just to reiterate the relevant facts for this issue:

We decided to merge the proposed run_tests functionality command, into the existing run command by adding a --classNames parameter.

To implement this, you will try to rewrite the lib/cli/test.js command in a fashion where it can easily be reused in an if/else or extended, whatever works best. Let me know, if you need any assistance in doing that or, if you find a simpler, more elegant solution than this, please let me know as well :)

amtrack commented 8 years ago

yep, that sounds like a plan!

minor correction: s/run/test/

janraasch commented 8 years ago

Let's continue in #42.