In "AAA" pattern where extraction of the act data should be written?
In the Act or in the Assert section?
Consider this Unit Test, the extraction of the two persons, should it be in the Act as in the example or in the Assert? we would like to make a standard for all of our UT in the company.
[Test]
public void Test()
{
// Arrange
var p1 = new Person();
var p2 = new Person();
Session.Save(p1);
Session.Save(p2);
// Act
var result = new PersonQuery().GetAll();
var firstPerson = result[0];
var secondPerson = result[1];
// Assert
Assert.AreEqual(p1.Id, firstPerson.Id);
Assert.AreEqual(p2.Id, secondPerson.Id);
}
(please ignore that in this simple test I can write Assert.AreEqual(p1.Id, result[0].Id);
)
I know it's not a huge problem, but I still want to know how to do things the best.
This should happen in the Assert phase:
[Test]
public void Test()
{
// Arrange
var p1 = new Person();
var p2 = new Person();
Session.Save(p1);
Session.Save(p2);
// Act
var result = new PersonQuery().GetAll();
// Assert
var firstPerson = result[0];
var secondPerson = result[1];
Assert.AreEqual(p1.Id, firstPerson.Id);
Assert.AreEqual(p2.Id, secondPerson.Id);
}
The Act
phase only involves invoking the method under test.
It depends, rule of thumb - Act stage represents execution of business logic under the test. In your case it depends on whether extraction affects any business logic, if result[i]
indexer is straightforward collection item accesor - it is not Act
since you alreay extracted data into the result
variable, otherwise - it would be Act
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With