What is the best way to run test classes from Apex code? SOAP Apis or Rest API?
Clash Royale CLAN TAG#URR8PPP
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty margin-bottom:0;
up vote
2
down vote
favorite
To run all tests or specific test classes we can use both the APIs SOAP and Rest API. Below are the differences that I noticed when done research on both.
All test- SOAP - Possible, Without mentioning a list of test classes
- REST - Not possible, You have to specify all classes that you want to run
Response- SOAP - Provide classes to handle test run results which makes it easy to get list of failed and passed test classes
- REST - Need to handle the JSON response by our own.
I want to run test classes from Apex code and based on that my requirements are,
To get a list of the failed, passed and aborted test classes list.
I should be able to run all tests with/without mentioning all classes.
unit-test rest-api soap-api
New contributor
add a comment |Â
up vote
2
down vote
favorite
To run all tests or specific test classes we can use both the APIs SOAP and Rest API. Below are the differences that I noticed when done research on both.
All test- SOAP - Possible, Without mentioning a list of test classes
- REST - Not possible, You have to specify all classes that you want to run
Response- SOAP - Provide classes to handle test run results which makes it easy to get list of failed and passed test classes
- REST - Need to handle the JSON response by our own.
I want to run test classes from Apex code and based on that my requirements are,
To get a list of the failed, passed and aborted test classes list.
I should be able to run all tests with/without mentioning all classes.
unit-test rest-api soap-api
New contributor
add a comment |Â
up vote
2
down vote
favorite
up vote
2
down vote
favorite
To run all tests or specific test classes we can use both the APIs SOAP and Rest API. Below are the differences that I noticed when done research on both.
All test- SOAP - Possible, Without mentioning a list of test classes
- REST - Not possible, You have to specify all classes that you want to run
Response- SOAP - Provide classes to handle test run results which makes it easy to get list of failed and passed test classes
- REST - Need to handle the JSON response by our own.
I want to run test classes from Apex code and based on that my requirements are,
To get a list of the failed, passed and aborted test classes list.
I should be able to run all tests with/without mentioning all classes.
unit-test rest-api soap-api
New contributor
To run all tests or specific test classes we can use both the APIs SOAP and Rest API. Below are the differences that I noticed when done research on both.
All test- SOAP - Possible, Without mentioning a list of test classes
- REST - Not possible, You have to specify all classes that you want to run
Response- SOAP - Provide classes to handle test run results which makes it easy to get list of failed and passed test classes
- REST - Need to handle the JSON response by our own.
I want to run test classes from Apex code and based on that my requirements are,
To get a list of the failed, passed and aborted test classes list.
I should be able to run all tests with/without mentioning all classes.
unit-test rest-api soap-api
unit-test rest-api soap-api
New contributor
New contributor
New contributor
asked 2 hours ago
allgood
132
132
New contributor
New contributor
add a comment |Â
add a comment |Â
1 Answer
1
active
oldest
votes
up vote
2
down vote
accepted
REST - Not possible, You have to specify all classes that you want to run
Wrong. Simply call the Tooling REST API as such:
/services/data/v43.0/tooling/runTestsAsynchronous/
"testLevel": "RunLocalTests"
This will run all tests without specifying names.
REST - Need to handle the JSON response by our own.
You can JSON2Apex from a sample response, so the heavy lifting is just a matter of parsing a class. No "manual" deserializing is necessary at a lower level.
However, since it is running asynchronously, all you get back is a job Id. To get the results later, query for them:
/services/data/v43.0/tooling/query?q=select+apexclass.name,Message,methodname,outcome,runtime,stacktrace+from+apextestresult+where+AsyncApexJobId=%277071T00006ErFY3%27
You'll want to monitor the AsyncApexJob to make sure that the status is either "success" or "failed" before querying for those results.
And, yes, you can do all this through the SOAP API, too. They are roughly analogous in functionality.
Thanks @sfdcfox! I was expecting reply from you. Do you think doing this thing synchronously makes a sense? Just to remind again, I want to do this thing in Apex only. You commented on one of the questions that for regression testing you were running the tests once in 24 hours and emailed that result. Did you used asynchronous or synchronous APIs in that?
â allgood
2 hours ago
@allgood Synchronous limits will prevent most reasonable sized orgs from running tests synchronously. You would need to check back every few minutes. If you're using Visualforce, an actionPoller would be appropriate, otherwise you'll want to set a callback after a few minutes (e.g. a queueable checking for results). P.S. if you're running tests in the current org, you can insert ApexTestQueueItem directly in Apex without a callout...
â sfdcfox
2 hours ago
@allgood I implemented this in pure Apex code for "the current org" by inserting ApexTestQueueItem records, then setting up a schedulable that checks back every five minutes until it's done.
â sfdcfox
2 hours ago
yes, my requirement is to run tests in current org but I think it will be an extra headache to prepare a list of all test classes and insert that list in ApexTestQueueItem when we want to run all tests. To get the list of all test classes again we need to use SOSL to find @isTest in classes, correct? :) suggested by you in one of the post.
â allgood
2 hours ago
@allgood Yes, it's really not that big of a deal. A few lines of code. I think the entire tool I wrote only ended up being 20-30 lines of code. It's not incredibly complicated.
â sfdcfox
2 hours ago
add a comment |Â
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
2
down vote
accepted
REST - Not possible, You have to specify all classes that you want to run
Wrong. Simply call the Tooling REST API as such:
/services/data/v43.0/tooling/runTestsAsynchronous/
"testLevel": "RunLocalTests"
This will run all tests without specifying names.
REST - Need to handle the JSON response by our own.
You can JSON2Apex from a sample response, so the heavy lifting is just a matter of parsing a class. No "manual" deserializing is necessary at a lower level.
However, since it is running asynchronously, all you get back is a job Id. To get the results later, query for them:
/services/data/v43.0/tooling/query?q=select+apexclass.name,Message,methodname,outcome,runtime,stacktrace+from+apextestresult+where+AsyncApexJobId=%277071T00006ErFY3%27
You'll want to monitor the AsyncApexJob to make sure that the status is either "success" or "failed" before querying for those results.
And, yes, you can do all this through the SOAP API, too. They are roughly analogous in functionality.
Thanks @sfdcfox! I was expecting reply from you. Do you think doing this thing synchronously makes a sense? Just to remind again, I want to do this thing in Apex only. You commented on one of the questions that for regression testing you were running the tests once in 24 hours and emailed that result. Did you used asynchronous or synchronous APIs in that?
â allgood
2 hours ago
@allgood Synchronous limits will prevent most reasonable sized orgs from running tests synchronously. You would need to check back every few minutes. If you're using Visualforce, an actionPoller would be appropriate, otherwise you'll want to set a callback after a few minutes (e.g. a queueable checking for results). P.S. if you're running tests in the current org, you can insert ApexTestQueueItem directly in Apex without a callout...
â sfdcfox
2 hours ago
@allgood I implemented this in pure Apex code for "the current org" by inserting ApexTestQueueItem records, then setting up a schedulable that checks back every five minutes until it's done.
â sfdcfox
2 hours ago
yes, my requirement is to run tests in current org but I think it will be an extra headache to prepare a list of all test classes and insert that list in ApexTestQueueItem when we want to run all tests. To get the list of all test classes again we need to use SOSL to find @isTest in classes, correct? :) suggested by you in one of the post.
â allgood
2 hours ago
@allgood Yes, it's really not that big of a deal. A few lines of code. I think the entire tool I wrote only ended up being 20-30 lines of code. It's not incredibly complicated.
â sfdcfox
2 hours ago
add a comment |Â
up vote
2
down vote
accepted
REST - Not possible, You have to specify all classes that you want to run
Wrong. Simply call the Tooling REST API as such:
/services/data/v43.0/tooling/runTestsAsynchronous/
"testLevel": "RunLocalTests"
This will run all tests without specifying names.
REST - Need to handle the JSON response by our own.
You can JSON2Apex from a sample response, so the heavy lifting is just a matter of parsing a class. No "manual" deserializing is necessary at a lower level.
However, since it is running asynchronously, all you get back is a job Id. To get the results later, query for them:
/services/data/v43.0/tooling/query?q=select+apexclass.name,Message,methodname,outcome,runtime,stacktrace+from+apextestresult+where+AsyncApexJobId=%277071T00006ErFY3%27
You'll want to monitor the AsyncApexJob to make sure that the status is either "success" or "failed" before querying for those results.
And, yes, you can do all this through the SOAP API, too. They are roughly analogous in functionality.
Thanks @sfdcfox! I was expecting reply from you. Do you think doing this thing synchronously makes a sense? Just to remind again, I want to do this thing in Apex only. You commented on one of the questions that for regression testing you were running the tests once in 24 hours and emailed that result. Did you used asynchronous or synchronous APIs in that?
â allgood
2 hours ago
@allgood Synchronous limits will prevent most reasonable sized orgs from running tests synchronously. You would need to check back every few minutes. If you're using Visualforce, an actionPoller would be appropriate, otherwise you'll want to set a callback after a few minutes (e.g. a queueable checking for results). P.S. if you're running tests in the current org, you can insert ApexTestQueueItem directly in Apex without a callout...
â sfdcfox
2 hours ago
@allgood I implemented this in pure Apex code for "the current org" by inserting ApexTestQueueItem records, then setting up a schedulable that checks back every five minutes until it's done.
â sfdcfox
2 hours ago
yes, my requirement is to run tests in current org but I think it will be an extra headache to prepare a list of all test classes and insert that list in ApexTestQueueItem when we want to run all tests. To get the list of all test classes again we need to use SOSL to find @isTest in classes, correct? :) suggested by you in one of the post.
â allgood
2 hours ago
@allgood Yes, it's really not that big of a deal. A few lines of code. I think the entire tool I wrote only ended up being 20-30 lines of code. It's not incredibly complicated.
â sfdcfox
2 hours ago
add a comment |Â
up vote
2
down vote
accepted
up vote
2
down vote
accepted
REST - Not possible, You have to specify all classes that you want to run
Wrong. Simply call the Tooling REST API as such:
/services/data/v43.0/tooling/runTestsAsynchronous/
"testLevel": "RunLocalTests"
This will run all tests without specifying names.
REST - Need to handle the JSON response by our own.
You can JSON2Apex from a sample response, so the heavy lifting is just a matter of parsing a class. No "manual" deserializing is necessary at a lower level.
However, since it is running asynchronously, all you get back is a job Id. To get the results later, query for them:
/services/data/v43.0/tooling/query?q=select+apexclass.name,Message,methodname,outcome,runtime,stacktrace+from+apextestresult+where+AsyncApexJobId=%277071T00006ErFY3%27
You'll want to monitor the AsyncApexJob to make sure that the status is either "success" or "failed" before querying for those results.
And, yes, you can do all this through the SOAP API, too. They are roughly analogous in functionality.
REST - Not possible, You have to specify all classes that you want to run
Wrong. Simply call the Tooling REST API as such:
/services/data/v43.0/tooling/runTestsAsynchronous/
"testLevel": "RunLocalTests"
This will run all tests without specifying names.
REST - Need to handle the JSON response by our own.
You can JSON2Apex from a sample response, so the heavy lifting is just a matter of parsing a class. No "manual" deserializing is necessary at a lower level.
However, since it is running asynchronously, all you get back is a job Id. To get the results later, query for them:
/services/data/v43.0/tooling/query?q=select+apexclass.name,Message,methodname,outcome,runtime,stacktrace+from+apextestresult+where+AsyncApexJobId=%277071T00006ErFY3%27
You'll want to monitor the AsyncApexJob to make sure that the status is either "success" or "failed" before querying for those results.
And, yes, you can do all this through the SOAP API, too. They are roughly analogous in functionality.
answered 2 hours ago
sfdcfox
235k10180396
235k10180396
Thanks @sfdcfox! I was expecting reply from you. Do you think doing this thing synchronously makes a sense? Just to remind again, I want to do this thing in Apex only. You commented on one of the questions that for regression testing you were running the tests once in 24 hours and emailed that result. Did you used asynchronous or synchronous APIs in that?
â allgood
2 hours ago
@allgood Synchronous limits will prevent most reasonable sized orgs from running tests synchronously. You would need to check back every few minutes. If you're using Visualforce, an actionPoller would be appropriate, otherwise you'll want to set a callback after a few minutes (e.g. a queueable checking for results). P.S. if you're running tests in the current org, you can insert ApexTestQueueItem directly in Apex without a callout...
â sfdcfox
2 hours ago
@allgood I implemented this in pure Apex code for "the current org" by inserting ApexTestQueueItem records, then setting up a schedulable that checks back every five minutes until it's done.
â sfdcfox
2 hours ago
yes, my requirement is to run tests in current org but I think it will be an extra headache to prepare a list of all test classes and insert that list in ApexTestQueueItem when we want to run all tests. To get the list of all test classes again we need to use SOSL to find @isTest in classes, correct? :) suggested by you in one of the post.
â allgood
2 hours ago
@allgood Yes, it's really not that big of a deal. A few lines of code. I think the entire tool I wrote only ended up being 20-30 lines of code. It's not incredibly complicated.
â sfdcfox
2 hours ago
add a comment |Â
Thanks @sfdcfox! I was expecting reply from you. Do you think doing this thing synchronously makes a sense? Just to remind again, I want to do this thing in Apex only. You commented on one of the questions that for regression testing you were running the tests once in 24 hours and emailed that result. Did you used asynchronous or synchronous APIs in that?
â allgood
2 hours ago
@allgood Synchronous limits will prevent most reasonable sized orgs from running tests synchronously. You would need to check back every few minutes. If you're using Visualforce, an actionPoller would be appropriate, otherwise you'll want to set a callback after a few minutes (e.g. a queueable checking for results). P.S. if you're running tests in the current org, you can insert ApexTestQueueItem directly in Apex without a callout...
â sfdcfox
2 hours ago
@allgood I implemented this in pure Apex code for "the current org" by inserting ApexTestQueueItem records, then setting up a schedulable that checks back every five minutes until it's done.
â sfdcfox
2 hours ago
yes, my requirement is to run tests in current org but I think it will be an extra headache to prepare a list of all test classes and insert that list in ApexTestQueueItem when we want to run all tests. To get the list of all test classes again we need to use SOSL to find @isTest in classes, correct? :) suggested by you in one of the post.
â allgood
2 hours ago
@allgood Yes, it's really not that big of a deal. A few lines of code. I think the entire tool I wrote only ended up being 20-30 lines of code. It's not incredibly complicated.
â sfdcfox
2 hours ago
Thanks @sfdcfox! I was expecting reply from you. Do you think doing this thing synchronously makes a sense? Just to remind again, I want to do this thing in Apex only. You commented on one of the questions that for regression testing you were running the tests once in 24 hours and emailed that result. Did you used asynchronous or synchronous APIs in that?
â allgood
2 hours ago
Thanks @sfdcfox! I was expecting reply from you. Do you think doing this thing synchronously makes a sense? Just to remind again, I want to do this thing in Apex only. You commented on one of the questions that for regression testing you were running the tests once in 24 hours and emailed that result. Did you used asynchronous or synchronous APIs in that?
â allgood
2 hours ago
@allgood Synchronous limits will prevent most reasonable sized orgs from running tests synchronously. You would need to check back every few minutes. If you're using Visualforce, an actionPoller would be appropriate, otherwise you'll want to set a callback after a few minutes (e.g. a queueable checking for results). P.S. if you're running tests in the current org, you can insert ApexTestQueueItem directly in Apex without a callout...
â sfdcfox
2 hours ago
@allgood Synchronous limits will prevent most reasonable sized orgs from running tests synchronously. You would need to check back every few minutes. If you're using Visualforce, an actionPoller would be appropriate, otherwise you'll want to set a callback after a few minutes (e.g. a queueable checking for results). P.S. if you're running tests in the current org, you can insert ApexTestQueueItem directly in Apex without a callout...
â sfdcfox
2 hours ago
@allgood I implemented this in pure Apex code for "the current org" by inserting ApexTestQueueItem records, then setting up a schedulable that checks back every five minutes until it's done.
â sfdcfox
2 hours ago
@allgood I implemented this in pure Apex code for "the current org" by inserting ApexTestQueueItem records, then setting up a schedulable that checks back every five minutes until it's done.
â sfdcfox
2 hours ago
yes, my requirement is to run tests in current org but I think it will be an extra headache to prepare a list of all test classes and insert that list in ApexTestQueueItem when we want to run all tests. To get the list of all test classes again we need to use SOSL to find @isTest in classes, correct? :) suggested by you in one of the post.
â allgood
2 hours ago
yes, my requirement is to run tests in current org but I think it will be an extra headache to prepare a list of all test classes and insert that list in ApexTestQueueItem when we want to run all tests. To get the list of all test classes again we need to use SOSL to find @isTest in classes, correct? :) suggested by you in one of the post.
â allgood
2 hours ago
@allgood Yes, it's really not that big of a deal. A few lines of code. I think the entire tool I wrote only ended up being 20-30 lines of code. It's not incredibly complicated.
â sfdcfox
2 hours ago
@allgood Yes, it's really not that big of a deal. A few lines of code. I think the entire tool I wrote only ended up being 20-30 lines of code. It's not incredibly complicated.
â sfdcfox
2 hours ago
add a comment |Â
allgood is a new contributor. Be nice, and check out our Code of Conduct.
allgood is a new contributor. Be nice, and check out our Code of Conduct.
allgood is a new contributor. Be nice, and check out our Code of Conduct.
allgood is a new contributor. Be nice, and check out our Code of Conduct.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsalesforce.stackexchange.com%2fquestions%2f237478%2fwhat-is-the-best-way-to-run-test-classes-from-apex-code-soap-apis-or-rest-api%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password