10

I'm trying to set up Jenkins to automate a daily task of running all tests in my sandbox (and eventually, production environment.

Typically, when I do a deploy or retrieve task, I get lots of output while the process in going:

[sf:retrieve] Request for a retrieve submitted successfully.
[sf:retrieve] Request Id for the current retrieve task: 04sJ00000005q0JIAQ
[sf:retrieve] Waiting for server to finish processing the request...
[sf:retrieve] Request Status: InProgress
[sf:retrieve] Request Status: InProgress
[sf:retrieve] Request Status: Completed

However, when I do a test task, I get one line, and then a big old nothing:

[sf:compileAndTest] compileAndTest on https://test.salesforce.com, compiling 0 classes and 0 triggers, deleting 0 classes and 0 triggers


.

Furthermore, there's no evidence in my org that anything is happening: nothing shows up on my Monitor Deployments page, and nothing shows up in my Test Execution monitoring page. It's really disconcerting, since running all tests can take 30+ min and I have no idea how it's going (or if it's actually happening at all).

Any tips for how I can get more useful feedback? Here's my ant target:

<target name="runTestsDev">
    <sequential>
        <echo>Running all tests in the "dev" environment.</echo>
        <sf:compileAndTest username="${sf.dev.username}"
                password="${sf.dev.password}"
                serverurl="${sf.testurl}">
            <runTests namespace="Default"/>
        </sf:compileAndTest>
    </sequential>
</target>

(It's actually more generic, and defined with macros -- just giving you the simplified version)

  • And just to be thorough, the following seemingly similar questions don't address my problem: salesforce.stackexchange.com/questions/654/…, salesforce.stackexchange.com/questions/12965/… – Benj Jul 4 '13 at 19:46
  • compileAndTest will be using the Apex API method of the same name. I don't think you can monitor the progress of this call. To run the tests and be able to monitor the progress you would need to create ApexTestQueueItem records. – Daniel Ballinger Jul 4 '13 at 20:57
  • @DanielBallinger hm. Is there support for that in the Migration Tool or another stable client? I'm trying to do a simple setup w/ ANT. Is there another way to run tests and get the results that I'm missing? – Benj Jul 5 '13 at 13:39
  • I guess I could deploy an empty package and choose runAllTests (although I really just want to limit it to my namespace). Is that what others are doing for this? – Benj Jul 5 '13 at 13:39
  • I haven't spent any time with the migration tool, so I tend to think of it from what the API provides. It is certainly possible to code up a command line tool that would queue all the classes in a namespace for testing and then monitor the progress. – Daniel Ballinger Jul 5 '13 at 19:53
6
+25

You can accomplish this by tweaking a few of the parameters in the deploy. Namely trace, pollWaitMillis, logType, and runTest. For example:

<target name="deploy">
  <sf:deploy username="${sf.username}" 
             password="${sf.password}" 
             serverurl="${sf.serverurl}" 
             maxPoll="${sf.maxPoll}" 
             checkOnly="true"
             runAllTests="false"
             logType="Detail"
             deployRoot="src"
             trace="true"
             pollWaitMillis="1000">
    <runTest>MyClass1</runTest>
    <runTest>MyClass2</runTest> <!--maybe you can use <runTests namespace="default">?-->
  </sf:deploy>
</target>

Alternatively, you could just build a simple Apex rest webservice that queues all non-namespaced tests, and call this webserivce from Jenkins using curl & ant. There is no harm in queuing non-test classes. These test results would appear in the "Apex Text Execution" section of the setup menu.

@HttpGet    
global static ResponseBody queueTests() {
    List<ApexTestQueueItem> items = new List<ApexTestQueueItem>();
    for(ApexClass ac : [SELECT Id FROM ApexClass WHERE NamespacePrefix = null]) {
        items.add(new ApexTestQueueItem(ApexClassId = ac.Id));
    }

    insert items;
    return new ResponseBody('success');
}    

If you wanted to do this kind of thing on demand, www.aside.io allows users to run unit tests by query from its "test" section. Click the "Run Some" button, and enter the following query:

SELECT Id FROM ApexClass WHERE NamespacePrefix = null
| improve this answer | |
  • Run All Tests causes all the AppExchange packaged tests to run, some of which fail. My question is "Do I have anything in my code that would fail to deploy" and so I need only my namespace to work. – Shane McLaughlin Jan 23 '14 at 21:08
  • 1
    Good catch, i'm meant the runTests element, will update answer. – Phil Rymek Jan 23 '14 at 22:49
  • Ideally, I wouldn't have to maintain this file with all the individual test names. I just want to run all tests that are non-namespaced. This is meant to be part of a chain of Jenkins jobs – Shane McLaughlin Jan 24 '14 at 5:30
  • Okay, added an option where you dont have to maintain the list. – Phil Rymek Jan 24 '14 at 15:34

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.