Testing in Dart: There’s life beyond Flutter.

João Augusto Perin
3 min readOct 23, 2020

Well, don’t get me wrong. I LOVE FLUTTER! I really do, and I can say that with some property. I was almost giving up on web/mobile development when I (don’t wanna waste your time with the whole story) suddenly met it.

But, Dart is also AWESOME! And people tend to only mention Flutter, and ending up just learning Dart to use Flutter. That’s the point, Dart can be used in other places!

So, these days I was wondering how could I make some scripts and random stuff in Dart, and came up to discover how to make some automated tests in it. Isn’t hard at all, but I decided I would write this article, ’cause some curious dude could end up reading and meeting more features of this awesome language! (Like you’re doing right now 😃)

So here we go!

Let’s start by creating a dart project using:

tests in dart being the name you want to the project

So, by Dart documentation:

Although your tests partly depend on the platform your code is intended for — Flutter, the web, or server-side, for example — the following packages are useful across Dart platforms: […]

Note that even dart documentation mention Flutter all the time, I would be mad if I don’t love Flutter the much I do.

So, install the test package in the created project, and let’s use it.

Now that we’re done, let’s start from the basics:

I think I could not make a simpler base file.

Let’s unit test it to see if this function really works (You know, maybe I messed thing up a bit).

Running it, I got:

But let’s get deeper:

Tip: You can use all of the matches of the Matcher package. 😉

And that’s It, for more resources, you can refer to Dart Official Documentation, see ya!

--

--

João Augusto Perin

I don’t know how to describe myself actually…maybe a hypothetical jedi? God no…that sounds like a bad album title from an underground 80’s band.