EVERYONE has been asking my thoughts on Tiger King. I’m a wildlife biologist with 17 years of experience and a long personal history of doing research on animals in captivity. In fact, because it’s…
Learn how to report test coverage of Swift packages without using Xcode. By running tests in a Linux machine, you can integrate the process in your CI/CD system using a Docker container.
Writing your own Swift packages is a good way of organizing your code base in reusable and easy to maintain libraries.
Think about an API that you access from more than one of your apps. Rewriting a Swift wrapper for each of your projects, without sharing code among them, is not only a waste of work, but also a way to add confusion to your team, which is now switching between different implementations of the same concept. It increases the chance of bugs in your code.
By moving the common code into a Swift package, it becomes the only source of truth for that code, making it easier to maintain.
You can work on a package directly in Xcode, and you can write tests and test your package, as you do with your apps. It is also possible to collect coverage data, using Xcode.
But you do not need Xcode, or even a mac, to work on and test a Swift package. In fact, the Swift ecosystem is open source, and it can be used on Linux to build and test Swift libraries and application.
In case you are not using Xcode, you need a different way to collect coverage information about your test suite, and that is exactly what I will show you in the rest of this article.
Test coverage information can be gathered easily. Open your terminal, or console, and change directory to the one containing your package. Then run swift test --enable-code-coverage
. After tests are executed, you are greeted with an output like
But where is the report about coverage? The swift test
command does not specify it:
If you prefer a different output format, unfortunately the current version of the swift test
command does not allow you to change it. But the tool it uses might allow it.
In fact, it does. If we run
The supported formats are: text (JSON), and lcov. We can run the same command swift test
uses, and change the format:
You can find the correct paths for you when you run swift test --enable-code-coverage --verbose
. You also might need to install a version of LLVM-cov.
which produces a 2003 looking website:
We use the result from the code coverage report to update our GitLab project, both for the merge request
and for the project itself
Planning to explore the hidden charm of Africa and want to begin the journey from the most charming country? Tanzania safari trip will be a wonderful experience for you that you will love to cherish…
Gina Gotthilf joined the Xoogler community for a Growth Series event moderated by Holly Chen to speak on her time at Duolingo, Tumblr, and Mike Bloomberg’s presidential campaign. She provided a wide…
Knowing this will help understand how to stop bad habits and start new ones. Do you know that emotion plays a key role in habit formation? A positive emotion is perceived as a reward by the brain…