Capturing Human Intelligence - ApprovalTests is an open source assertion/verification library to aid unit testing.
It is compatiable with JUnit 3 & JUnit 4.
Approval Tests can be used for verifing objects that require more than a simple assert. They also come prepackaged with utilities for some common .Net scenarios including
- HashMaps & Collections
- Long Strings
- Log Files
- JPanels
- Xml
- Html
- Json
You can watch a bunch of short videos on getting started and using ApprovalTests in Java at youtube
If you prefer auditory learning, you might enjoy the following podcast (Note: Some of these talk about the .net side)
- [Hanselminutes] (http://www.hanselminutes.com/360/approval-tests-with-llewellyn-falco)
- Herding Code
- The Watir Podcast
You can download the ApprovalTests jar at: [http://sourceforge.net/projects/approvaltests/files/ApprovalTests.Java/]
ApprovalTests eats it own dogfood, so the best examples are in the source code itself.
None the less, Here's a quick look at some Sample Code
public class SampleArrayTest extends TestCase
{
public void testList() throws Exception
{
String[] names = {"Llewellyn", "James", "Dan", "Jason", "Katrina"};
Arrays.sort(names);
Approvals.verifyAll("", names);
}
}
Will Produce a File
SampleTest.TestList.recieved.txt
[0] = Dan
[1] = James
[2] = Jason
[3] = Katrina
[4] = Llewellyn
Simply rename this to SampleTest.testList.approved.txt and the test will now pass.
The *.approved.*
files must be checked into source your source control. This can be an issue with git as it will change the line endings.
The suggested fix is to add
*.approved.* binary
to your .gitattributes
twitter: @LlewellynFalco or #ApprovalTests