function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
davcondevdavcondev 

How to run unmanaged class tests only during sandbox ant deployment?

According to the KB article linked, setting runAllTests to false for production ant deployments will exclude only managed package tests.

 

Is there a way to run unmanaged code tests only for sandbox ant deployments?

 

http://help.salesforce.com/apex/HTViewSolution?id=000003620&language=en_US

Best Answer chosen by Admin (Salesforce Developers) 
GSBassoGSBasso

You can, but it's non-trivial.

 

As you may now know, setting runAllTests to false will not run any tests in a sandbox, and setting the value to true will run all tests, including managed.

 

The only way to run the tests you want (i.e. only unmanaged) is to explicitly specify them as follows:

 

<sf:deploy 
    username="${sf.usr}" 
    password="${sf.pwd}" 
    serverurl="${sf.url}" 
    pollWaitMillis="30000"
    maxPoll="120"
    zipFile="${user.dir}/${srs}.zip"
    runAllTests="false"
    checkOnly="${sf.test}" 
    ignoreWarnings="${ignoreWarnings}"
>
    <runTest>test1</runTest>
    <runTest>test2</runTest>
</sf:deploy>

 

What we actually do is maintain our list of unmanaged tests in a separate manifest and then embed it into our build.xml file as follows:

 

<!DOCTYPE project [
   <!ENTITY tests SYSTEM "runTests.xml">
]>



<sf:deploy 
    username="${sf.usr}" 
    password="${sf.pwd}" 
    serverurl="${sf.url}" 
    pollWaitMillis="30000"
    maxPoll="120"
    zipFile="${user.dir}/${srs}.zip"
    runAllTests="false"
    checkOnly="${sf.test}" 
    ignoreWarnings="${ignoreWarnings}"
>
    &tests;
</sf:deploy>

 

The content of runTests.xml would look like:

 

<runTest>test1</runTest>
<runTest>test2</runTest>

 

Hopefully this helps.