Skip to main content

Concise Apex Test Output in the CLI

·2 mins

Improving the developer experience when running apex tests.

Art of a computer terminal.

The power of open source software is that it is community driven, so that anyone can make meaningful contributions, even when that contribution feels small.

One example of this is my recent contribution to the Salesforce CLI to improve apex test result output. I was unhappy with the current state. Every test method’s result is outputted to the terminal, whether it succeeds or fails. So if you have many tests this would require you to scroll through a lot of other results before you can pinpoint which test is the problem.

For example, here is the output of the command sf apex run test -w5 in an org with 14 tests.

Long terminal output with 1 failing test.

This is longer than it needs to be, and represents a fairly small org. Only 1 test is failing, but it is buried behind the passing test results. In a larger org, there could be hundreds of tests, making it very cumbersome to find the test holding up a deployment.

Searching through the CLI repo, this was brought up as a pain point at least a couple of times: #243, #2872.

After discussing possible solutions, I took it upon myself to implement a fix by adding a new flag to the apex run test and apex get test commands: --concise.

Using this flag will now skip the output of passing test results and only display test results that failed.

Here is the output of the command sf apex run test -w5 --concise in the same org.

Concise terminal output with 1 failing test.

The terminal output is much easier to read, as only failures are displayed. If no tests fail, then only the Test Summary table is shown.

This feature is part of the stable release candidate for August 28th. Check out the release notes and try it out!


Comments or questions? Send me a message