---
title: "Discussion on \"12 Tips for Writing Better Automated Tests\" | Hashnode"
description: "Discussion on \"12 Tips for Writing Better Automated Tests\". Automated tests are one of the core principles for writing maintainable code. When we have tests, we can refactor code without worrying we might break existing code. They also, help us catch bugs that would otherwise end up in production. Good tests ..."
url: "https://hashnode.com/posts/12-tips-for-writing-better-automated-tests/60190d3958cc670f3df45ae6"
---

[Feed](https://hashnode.com/feed) /

Discussion

# [12 Tips for Writing Better Automated Tests](https://kaca.hashnode.dev/12-tips-for-writing-better-automated-tests?utm_source=hashnode&utm_medium=feed)

Automated tests are one of the core principles for writing maintainable code. When we have tests, we can refactor code without worrying we might break existing code. They also, help us catch bugs that would otherwise end up in production. Good tests ...

Feb 2, 2021 · 13 min read · kaca.hashnode.dev  
Read the article

-   [#web-development](https://hashnode.com/tag/web-development)
-   [#testing](https://hashnode.com/tag/testing)
-   [#programming](https://hashnode.com/tag/programming)

## Written by

[Dino Kacavenda](https://hashnode.com/@kaca)

@kaca · Croatia, Zagreb

  
[View profile](https://hashnode.com/@kaca)

Full Stack Developer

Full Stack Engineer with a Master's degree in Computing, with more than 5 years experience in developing enterprise-level applications.

## Responses 3

Markdown supported · ⌘↵ to post

[Luís Soares](https://hashnode.com/@lsoares)

[Feb 9, 2021](https://hashnode.com/posts/12-tips-for-writing-better-automated-tests/60190d3958cc670f3df45ae6/comment/6021d78e281265375d6436d4)

Nice article! My 2 cent: Usually, I don't agree with "Avoid magic numbers or strings". [I wrote an article about it](https://levelup.gitconnected.com/when-magic-numbers-are-not-magic-fcdf034295a5). I prefer [DAMP](https://enterprisecraftsmanship.com/posts/dry-damp-unit-tests/) and Evident Data (Kent Beck).

I'd do instead:

```
const userPosts = callToGetUserPosts();
expect(userPosts).toBe(1);
```

which is a self-documenting single-liner.

[Dino Kacavenda](https://hashnode.com/@kaca)

[Feb 9, 2021](https://hashnode.com/posts/12-tips-for-writing-better-automated-tests/60190d3958cc670f3df45ae6/comment/6021d78e281265375d6436d4#reply-60223e04281265375d643da0)

Thank you for reading the article :). I agree with things you wrote in your article, what I meant by avoiding magic values is to approve the readability of tests when you have some complex setups (for example you setup a database to test your repository layer). In those cases, I have found it is very hard to determine what some value means. If values are self-evident like in your example then I completely agree that you can inline the value.

[Luís Soares](https://hashnode.com/@lsoares)

[Feb 9, 2021](https://hashnode.com/posts/12-tips-for-writing-better-automated-tests/60190d3958cc670f3df45ae6/comment/6021d78e281265375d6436d4#reply-60225f71281265375d64434e)

[Dino Kacavenda](https://hashnode.com/@kaca) thanks for reading my article. my point is that there rarely is the need of creating constants. And when there is, perhaps there's a smell around it. maybe you can find a better example 🤓

[Maxi Contieri](https://hashnode.com/@mcsee)

[Feb 2, 2021](https://hashnode.com/posts/12-tips-for-writing-better-automated-tests/60190d3958cc670f3df45ae6/comment/60195a0f58cc670f3df464b2)

Great Article !

I think every new developer should read it

I'd add 'Make Zombie Testing'
