0: Introduction — Testing In Flutter

Berat Göktuğ Özdemir
3 min readApr 5, 2022

Hi, I am Göktuğ. I am a Software Developer at Paraşüt and an organizer of Flutter Turkey. My Flutter journey started in November 2018.

Majid Hajian’s tutorial about testing inspired me to write this complete series of testing in Flutter.

Table Of Contents

  • About the series
  • What is a Test?
  • Why do we need to write tests?
  • What is the cost of writing tests?
  • Test-Driven Development

About the series

I’ve created a Flutter Testing project on GitHub. You can find the project here.

I will try to explain the testing methods and describe the code in the following articles. This series will contain different kinds of testing methods such as Unit Test, Widget Test, Integration Test, Bloc Test, Golden Test, Firebase Test Lab, and more. Each testing method will be an article.

What is a Test?

“Software testing is the process of evaluating and verifying that a software product or application does what it is supposed to do. The benefits of testing include preventing bugs, reducing development costs, and improving performance.”
-
https://www.ibm.com/topics/software-testing

Basically, tests aim to find errors and help us to make our application error-free.

Why do we need to write tests?

It is hard to test everything manually. Did you change something on the code? You need to test all the connected logic, UI, and other parts manually every time.

What if you prefer automated testing? Your tests always run. Did you change the calculation logic? Just run the tests. Did you change the loading view of your app? Just run the tests. Did you change the order of your pages? Just run the tests.

In fact, if you set some scripts on GitHub Action, Bitbucket Pipeline, Codemagic, etc., all the tests will run on your CI/CD service for each push, commit, and PR. In this way, you will be sure everything works fine.

What is the cost of writing tests?

Comparation of different kinds of testing
  • Unit Tests are easy to write. Execution speed is fast, and the maintenance cost is low.
  • Widget Tests are easier than Integration tests. Execution speed is still fast, but the maintenance cost is high.
  • Integration Tests are the hardest to write. The execution speed is slow excessively, and the maintenance cost is also overly high.

Test-Driven Development

Test-Driven Development (TDD) is a software development approach in which test cases are developed to specify and validate what the code will do.

In this approach, test cases are specified, and the tests will be written before the code. Then, the code will be written, and it should pass all the test cases. This helps to avoid duplication of code.

There are five steps of TDD.

  1. Add a test.
  2. Run all tests and see if any new test fails.
  3. Write some code.
  4. Run tests and refactor code.
  5. Repeat
Five Steps of Test-Driven Development

If you are interested in the TDD approach in Flutter, you can check out the Flutter TDD Clean Architecture Course of Matt Rešetár(Reso Coder).

Other Articles in this series

🎉 Thanks for your time!

💙 You can find me on Twitter and Linkedin. You can find everything about me here.

👉🏻 You can find all the source code on Github.

--

--