Unit testing a Dart server

Suragch
Flutter Community
Published in
14 min readJan 9, 2021

--

Part 3 in a series about Server Side Dart without a framework

Dart testing

If you haven’t read the first two parts of this series, you may want to start with them because they’ll provide a lot of background information that I won’t reexplain today:

  1. Building a Dart server from scratch
  2. Routing HTTP requests in a Dart server

If you’re comfortable with those topics, though, there’s no need to refer to them. This article will contain all the code you need to follow along.

Note: I’m using the pre-null safe version of Dart (2.10.4) to write this article, but I plan to update the instructions when null safety enters stable.

Another note: This tutorial series is about building a Dart server without a framework or any third party packages. Today’s article will use the test package (which you could also call a testing framework), but I’m not counting that since it’s made by the Dart team and isn’t related to the server code itself. Don’t hold me to my words too literally. What I mean is we won’t use Aqueduct or Shelf or even the http_server library.

OK, one more note: I’m assuming you already know a little about unit testing. This tutorial doesn’t require much prior knowledge, but if you don’t even know how to run a test or what an expect statement does, then you

--

--