7

is there a possibility for Run all tests (in target sandbox) before deployment from my dev sandbox? If so how to do that?

I have about 700 components in my changeset and its successfully validated. But I read in SF help that run all test have to be done manually.

If that is the case after I deploy and say run all tests, and if it fails, is a possiblity to roll back?

(or)

Can I do a run all tests after validating my changeset somehow? (i know its foolishness to ask this question because it might not have the components to run all tests. just wanted to know if there is tweak somehow? :) )

9

You can force a run of all tests when deploying using the Force.com migration tool which is a wrapper over Ant. Set runAllTests=true when deploying to simulate a production like deployment where all tests are run while deploying. To rollback if test classes fail, set the rollBackOnError deployment option to true.

Here is the reference documentation, look around page 17 (Deploying Code) http://www.salesforce.com/us/developer/docs/daas/salesforce_migration_guide.pdf

| improve this answer | |
  • Thanks @techtrekker. can we also validate it through force.com migration tool? – Sathya Oct 14 '12 at 7:53
  • 3
    If you set the checkOnly attribute to true and have runAllTests=true, I would think that does a validate only deployment. If you want to run a validate only and deploy if successful then as described in my answer. – techtrekker Oct 14 '12 at 8:31
  • @techtrekker is there any way we can run tests only in the default namespace. I did settings as per your comment, now its running tests for all including code in packages, is there any way to just run code from our org? Thanks ! – Prafulla Patil Jun 19 '13 at 3:49
  • 1
    @PrafullaPatil, yes, it's possible in the following manner <sf:deploy username=...> <!-- List of unit tests which should be fired during deployment --> <runTest>UnitTestNameFromYourOrg_2</runTest> <runTest>UnitTestNameFromYourOrg_1</runTest> <runTest>...</runTest> <runTest>UnitTestNameFromYourOrg_N</runTest> </sf:deploy> – Pavel Slepiankou Jun 19 '13 at 5:54
  • Is there any way to run all test classes in Default namespace, but not the ones are part of installed apps ? – Prafulla Patil Jun 19 '13 at 19:45
2

I'm happy to report that as of Summer '15 (v34.0) there is now a testLevel parameter on the sf:deploy command so if you're using the Summer '15 version of ant-salesforce.jar you can now specify:

<target name="deployCodeCheckOnly">
  <sf:deploy 
    testLevel="RunLocalTests"
    username="username@username.be.full" 
    password="password" 
    serverurl="https://test.salesforce.com" 
    maxPoll="500" 
    deployRoot="codepkg" 
    checkOnly="true"/>
</target>

This will specifically exclude any Managed Package tests from running. There are a number of other changes to the test options for deployments in Summer '15 that you can read about here. The available testLevel options are:

  • NoTestRun—No tests are run. This test level applies only to deployments to development environments, such as sandbox, Developer Edition, or trial organizations. This test level is the default for development environments.
  • RunSpecifiedTests—Only the tests that you specify in the runTests option are run. Code coverage requirements differ from the default coverage requirements when using this test level. Each class and trigger in the deployment package must be covered by the executed tests for a minimum of 75% code coverage. This coverage is computed for each class and trigger individually and is different than the overall coverage percentage.
  • RunLocalTests—All tests in your organization are run, except the ones that originate from installed managed packages. This test level is the default for production deployments.
  • RunAllTestsInOrg—All tests are run. The tests include all tests in your organization, including tests of managed packages

See the Force.com Migration Tool documentation

| improve this answer | |
  • Just a note on this, in case anyone is in the same boat as we were... the fact that "NoTestRun" is the default for sandboxes means that if you have an ant deploy target that has runAllTests=true but does not specify testLevel, and you simply upgrade your ant-salesforce.jar to v34, suddenly, your sandbox deploys will still appear to work but no tests will be run! This caught us by surprise. – jkraybill Jun 10 '15 at 4:36
2

I was getting an error complaining that testLevel wasn't a valid parameter - turned out I had copied the ant.salesforce.jar to my ant/lib directory when I first configured the migration tool - I deleted it and reference the jar from within build.xml - works fine now. Keep that in mind if you upgrade to v34 of the migration tool that you should do a quick sweep of your system to make sure you don't have older versions of the jar out there in the classpath somewhere.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.