Julia v1.5 Testing: Best Practices

Do you think running tests are too slow? Cannot figure out how to do Test Driven Development (TDD) in Julia? Here is a guide.

Erik Engheim
6 min readJan 23, 2021

--

A lot of programming provide you with ready made solutions where there is one particular way of doing things. In the Julia community the approach is more around supply flexible building blocks from which you can construct whatever solution you want.

Read more: Julia v1.5 Testing: How to Organize Tests.

The advantage of this approach is that you can easily tailor a solution to your particular needs. The downside is that to someone fresh to Julia, it may not be immediately obvious what blocks to combine. One example of this is the Julia testing framework. It is flexible and can easily be tailored to your needs. But that also means it is not immediately obvious how you do many common workflows.

In this story I aim to show you patterns to follow for different use cases such as:

  • A thorough, correct and complete test run of a package. What you may want to do after downloading a new package you are uncertain about, or the kind of test you run at the end of day of coding.
  • Regular testing that you do with some frequency while developing.
  • Rapid iteration testing for when you run tests really frequently. E.g. because you follow TDD (Test Driven Development). In this case individual tests you are adding need to run fast, because they are run a lot.

Infrequent and Correct Testing

Say you are developing a package named Foobar which you want to test.

Minor digression. Anyone wondering about the name Foobar? It is just a nonsense word used by us programmers. Whenever you see the words foo, bar, baz and foobar you should know these are just placeholder names. You are meant to fill in something more useful.

Anyway this is the steps a Julia beginner may take to run their first package tests:

$ cd Foobar
$ julia
julia> ]
(@v1.5) pkg>
(@v1.5) pkg> activate .
(Foobar) pkg>
(Foobar) pkg> test
Testing Foobar
Status

--

--

Erik Engheim

Geek dad, living in Oslo, Norway with passion for UX, Julia programming, science, teaching, reading and writing.