Three Amigos of Unit Testing: Arrange, Act, Assert

Hi there, welcome back to my blog! Let me introduce you to the world of unit testing your code and get you started writing better software!

When I first started coding I didn’t know anything about testing. In fact, I went unit test free for over a year and a half. And I was convinced I was fine.

It was a typical scenario where if it isn’t broke, why fix it?

Except just because it seemed to be working, did not mean it wasn’t broken.

Note: for this series of blogs I’ll be focusing on C# and NUnit.

Ok, so what are those three amigos that I mention in the post title? Well those are the three As of unit testing: Arrange, Act, Assert.

Arrange is where you will set up the object that you want to test.

Act is where you will implement the method you want to run.

And finally, assert is where you check if the code returns what you would expect it to.

I found figuring out these terms helped me get to grips with how I could lay out my test. I say could, because I also quickly found out that everyone has there own ways of writing tests.

Which is confusing when you get taught a specific way! But most of my coding journey has been realising there’s 100s of ways to get the right answer so I’m going to focus on introducing you to the basics so you can find your own way.

A bonus tip I learned is when naming the new instance of the class that you want to test, by naming it ‘sut’ (which stands for system under test) it really saves on time thinking up names. But I’ll explain that in more detail when we get around to coding!

Now we have those key terms out of the way, come back tomorrow and I’ll introduce you to the important attributes of NUnit.

One response to “Three Amigos of Unit Testing: Arrange, Act, Assert”

  1. […] we are going to write the Assert part of the test. Remember my previous post where we discussed the three As of unit testing. Well this is the final one: Assert. And it’s easy enough to spot because we need to use the […]


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: