Capturing Human Intelligence - ApprovalTests is an open source assertion/verification library to aid unit testing.
ApprovalsTest Swift is compatible with the XCUnit testing framework
Approval Tests can be used for verifying objects that require more than a simple assert.
You can watch a bunch of short videos on getting started and using ApprovalTests in .Net at YouTube
If you prefer auditory learning, you might enjoy the following podcast
CocoaPods
target 'MyApp' do
use_frameworks!
# Pods for MyApp
target 'MyAppTests' do
inherit! :search_paths
# Pods for testing
pod 'ApprovalTests_Swift', :git => 'https://github.com/approvals/ApprovalTests.Swift.git'
end
end
class SampleTest: XCTestCase {
func testList() throws {
var names: [String] = ["Llewellyn", "James", "Dan", "Jason", "Katrina"]
names.sort()
try Approvals.verifyAll("", names);
}
}
Will Produce a File
SampleTest.testList.received.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. ApprovalTests now ignores line endings by default (so you can remove *.approved.* binary
from your .gitattributes file if you added previously).
If you would like to verify line endings, simply add [assembly: IgnoreLineEndingsAttribute(false)]
to your AssemblyInfo.cs
Do not add *.received.*
files to your source control (they are transitory, and some SCMs like TFS will lock them or mark them read-only, which will break every dependent test).
ask on twitter: @LlewellynFalco or #ApprovalTests