2

We are trying to run unit tests for [My Namespace] from Jenkins. We are writing Java JUnit tests. We would like to know how we can invoke unit test from SOAP api.

There is a reference to run unit tests here - https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_testing_unit_tests_running.htm

And I ended up here to runTests() - https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/sforce_api_calls_runtests.htm

But I don't know what is apexBinding variable in the example.

How can I trigger unit tests from Jenkins using Java? Does salesforce expose such functionality through an API?

1

There are a few APIs that you can use. The two basic modes that I would consider for a Jenkins set up would be the Ant Migration Tool or SFDX.

TestLevel

The TestLevel parameter (in the following examples) may be RunSpecifiedTests, RunLocalTests, or RunAllTestsInOrg (includes managed code).

Ant Migration Tool

Set a target in ant that looks like this.

<target name="runAllTests">
  <sf:deploy username="${username}" password="${password}"
      serverurl="${serverurl}" deployroot="${root}"
      checkonly="true" testLevel="RunAllTestsInOrg" />
</target>

You can look at the documentation for deploy for more options.

SFDX CLI

The Salesforce DX CLI includes commands to run tests in several different ways.

sfdx force:apex:test:run [-u usernameOrAlias]
   [-s TestSuites | -n ClassNames | -t TestMethods | -l TestLevel ]

You can look at the documentation for force:apex:test:run for more details.

API

You can use the API in Java, .Net, C++, PHP and others that support WSDLs. You can use this as a last resort, but to simply get up and running, I'd suggest you use an already-built tool if you can. The apexBinding is the WSDL for executing Apex Code, which you can download from the Setup screen under Develop > API.

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.