Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Java Unit Testing in Java How to Test Assertions

Mike B
Mike B
10,424 Points

The Action aspect of the AAA in junit

Referring to Craig's example with refunding money, I'm confused over what is considered an "action". In the first test, addingFunds() was an action (this makes cents to me...get it?..cents...nevermind) but in the second test addingFunds() is part of the Arranging. Shouldn't addingFunds() be an action?

1 Answer

Miguel Canas
Miguel Canas
Python Development Techdegree Student 11,470 Points

All the A's should be relative to the individual test case that you're creating. So let's consider the test cases.

In the first test case, we wanted to test that adding funds increments the available funds. In order to do that we needed to:

  • Arrange our test case by instantiating the Creditor class,
  • Act by calling the addFunds() method, and
  • Assert by asserting that addFunds() does in fact add the expected amount.

But in the second test case, we want to test that refunding returns all available funds. This test case implies that available funds should be available in order for the test to case to be valid. In order to do that we needed to:

  • Arrange our test by instantiating the Creditor class and calling addFunds() to add to the available funds.
  • Act by calling the refund() method, and
  • Assert by asserting that the result of calling the refund() method resets the available funds to zero.