Integrate Slather to Trendyol Project
The dream of every software developer is to write Unit and UI tests and automate the whole building process.
This dream becomes reality in Trendyol.
Software development is a process in which change is inevitable. We run unit tests in Jenkins’s platform to make sure the implemented changes do not cause problems in the system and work as expected.
After the unit tests were successfully completed, we wanted to see the test coverage results. Even though Apple displayed results within the Xcode, they were too generalized. We needed focus on a more specified level, with possibly an extra feature. In the end, we came to the conclusion that Slather would be one of the best choices for our needs.
Slather
Slather readme file is very informative. We added Slather into the last step of Jenkins’s automation process. Jenkins is configured to run unit tests after opening a pull request or pushing a new commit into pr. If all tests are successfully completed, Slather starts to calculate test coverage. At the end of the process another automation tool, Skynet, sends Slack notification for test coverage results. You can read the details of automation bot process here.
Integration
We ran the following command line in the terminal to download Slather:
gem install slather
We activated the code coverage feature option to view the test results. This option is under the test section tab of the editing scheme. Otherwise, Slather cannot calculate coverage.
Create a Yml File
Slather has a configuration file whose type is yml.
We divided our project into modules for an easy development process and decided to create a configuration file to cover different unit tests for each of the related modules.
We needed to move the configuration file to “.slather.yml” to be able to utilize these files.For instance, to use the “.Checkout-slather.yml” file, we ran the following command in the Jenkins pipeline script:
sh 'mv .' + testPlan + '-slather.yml .slather.yml'
Each configuration file except the main one has different modules for calculating test coverage whereas the main one includes all modules. The main configuration file is executed after a new pull request is opened. When a new commit is pushed to pr, Slather executes the configuration file of this pull request’s modules. In this way, we achieved to reduce Slather’s running time for new commits. Well, how did we create and separate configuration files?
Create Configuration File
As an example, let’s examine the above Slather file created for Checkout modules.
- We assigned to project’s xcodeproj and workspace names to the xcodeproj and workspace parameters as values. (Line 1–2)
- We defined the type of scheme that runs the unit tests. (Line 3)
- We defined the output_directory parameter value which Slather results will be added. (Line 4)
- We added related modules under the binary_basename parameter. (Line 5- 10)
- Unit tests are only written for the presenter classes in the project.We listed those class names under the ignore parameter to exclude other classes in the project from the test coverage (Line 11 -23).
The command below must be executed to view Slather results in the local environment, after the unit test process is completed:
slather coverage --show --html
Afterwards, the test coverage results will be shown in the browser as follows:
We see this result thanks to Jenkins.
I tried to explain how to use Slather in our Jenkins process. I hope you enjoyed reading. If you have any questions, do not hesitate to leave a comment below 🙂. Thank you for reading!