Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Arrange/Act/Assert (AAA) principle #1

Open
virtualitems opened this issue Dec 27, 2023 · 0 comments
Open

Arrange/Act/Assert (AAA) principle #1

virtualitems opened this issue Dec 27, 2023 · 0 comments

Comments

@virtualitems
Copy link
Owner

The Arrange/Act/Assert (AAA) principle is a pattern for structuring unit tests. It divides the test method into three sections: Arrange, Act, and Assert. Each section has a specific responsibility in the test process.

  • Arrange: In this section, you set up the necessary conditions and initialize the objects required for the test. This may involve creating objects, setting up variables, or any other preparation needed for the test.
  • Act: The Act section involves invoking the method or action being tested. This is where you perform the specific action or operation that you want to test.
  • Assert: In the Assert section, you verify the outcome or result of the test. This is where you check whether the expected behavior or outcome has been achieved. You may use assertions or other verification techniques to validate the results.

By following the AAA principle, you can structure your tests in a clear and organized manner, making them easier to read, understand, and maintain. This pattern helps separate the setup and verification steps from what is being tested, clarifies the necessary test steps, and highlights potential issues in the code.

Here's an example of how a test method might be structured using the AAA pattern:

// Arrange
var repository = Substitute.For<IClientRepository>();
var client = new Client(repository);

// Act
client.Save();

// Assert
mock.Received().SomeMethod();

In this example, the Arrange section sets up the necessary objects and dependencies for the test. The Act section invokes the Save method on the client object. Finally, the Assert section verifies that the SomeMethod was called on the mock object.

The AAA pattern provides a clear and concise way to organize unit tests, making them more readable and maintainable. It is widely adopted in software development and can be used for both functional and non-functional testing.

I hope this explanation helps! Let me know if you have any more questions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant