This project has a new name and home!
You can now find iOSSnapshotTestCase
here.
Snapshot view unit tests for iOS
License: MIT License
This project has a new name and home!
You can now find iOSSnapshotTestCase
here.
Steps to reproduce:
ios-snapshot-test-case
demo project: git clone [email protected]:facebook/ios-snapshot-test-case.git
FBSnapshotTestCaseDemo/FBSnapshotTestCaseDemo.xcodeproj
Actual result:
Build fails with following error:
CompileC /Users/ramzes/Library/Developer/Xcode/DerivedData/FBSnapshotTestCaseDemo-crephtwyyhgsmsevtxsznsqmwhmy/Build/Intermediates/FBSnapshotTestCaseDemo.build/Debug-iphonesimulator/FBSnapshotTestCaseDemoTests.build/Objects-normal/i386/FBSnapshotTestCase.o /Users/ramzes/Downloads/ios-snapshot-test-case/FBSnapshotTestCase.m normal i386 objective-c com.apple.compilers.llvm.clang.1_0.compiler
cd /Users/ramzes/Downloads/ios-snapshot-test-case/FBSnapshotTestCaseDemo
export LANG=en_US.US-ASCII
export PATH="/Applications/Xcode6-Beta.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin:/Applications/Xcode6-Beta.app/Contents/Developer/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin"
/Applications/Xcode6-Beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang -x objective-c -arch i386 -fmessage-length=0 -fdiagnostics-show-note-include-stack -fmacro-backtrace-limit=0 -std=gnu99 -fobjc-arc -fmodules -fmodules-cache-path=/Users/ramzes/Library/Developer/Xcode/DerivedData/ModuleCache -fmodules-prune-interval=86400 -fmodules-prune-after=345600 -Wnon-modular-include-in-framework-module -Werror=non-modular-include-in-framework-module -Wno-trigraphs -fpascal-strings -O0 -Wno-missing-field-initializers -Wno-missing-prototypes -Werror=return-type -Wno-implicit-atomic-properties -Werror=deprecated-objc-isa-usage -Werror=objc-root-class -Wno-receiver-is-weak -Wno-arc-repeated-use-of-weak -Wduplicate-method-match -Wno-missing-braces -Wparentheses -Wswitch -Wunused-function -Wno-unused-label -Wno-unused-parameter -Wunused-variable -Wunused-value -Wempty-body -Wuninitialized -Wno-unknown-pragmas -Wno-shadow -Wno-four-char-constants -Wno-conversion -Wconstant-conversion -Wint-conversion -Wbool-conversion -Wenum-conversion -Wshorten-64-to-32 -Wpointer-sign -Wno-newline-eof -Wno-selector -Wno-strict-selector-match -Wundeclared-selector -Wno-deprecated-implementations -DDEBUG=1 -DDEBUG=1 -DFB_REFERENCE_IMAGE_DIR=\"/Users/ramzes/Downloads/ios-snapshot-test-case/FBSnapshotTestCaseDemo/FBSnapshotTestCaseDemoTests/ReferenceImages\" -isysroot /Applications/Xcode6-Beta.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator8.0.sdk -fexceptions -fasm-blocks -fstrict-aliasing -Wprotocol -Wdeprecated-declarations -g -Wno-sign-conversion -fobjc-abi-version=2 -fobjc-legacy-dispatch -mios-simulator-version-min=6.0 -iquote /Users/ramzes/Library/Developer/Xcode/DerivedData/FBSnapshotTestCaseDemo-crephtwyyhgsmsevtxsznsqmwhmy/Build/Intermediates/FBSnapshotTestCaseDemo.build/Debug-iphonesimulator/FBSnapshotTestCaseDemoTests.build/FBSnapshotTestCaseDemoTests-generated-files.hmap -I/Users/ramzes/Library/Developer/Xcode/DerivedData/FBSnapshotTestCaseDemo-crephtwyyhgsmsevtxsznsqmwhmy/Build/Intermediates/FBSnapshotTestCaseDemo.build/Debug-iphonesimulator/FBSnapshotTestCaseDemoTests.build/FBSnapshotTestCaseDemoTests-own-target-headers.hmap -I/Users/ramzes/Library/Developer/Xcode/DerivedData/FBSnapshotTestCaseDemo-crephtwyyhgsmsevtxsznsqmwhmy/Build/Intermediates/FBSnapshotTestCaseDemo.build/Debug-iphonesimulator/FBSnapshotTestCaseDemoTests.build/FBSnapshotTestCaseDemoTests-all-target-headers.hmap -iquote /Users/ramzes/Library/Developer/Xcode/DerivedData/FBSnapshotTestCaseDemo-crephtwyyhgsmsevtxsznsqmwhmy/Build/Intermediates/FBSnapshotTestCaseDemo.build/Debug-iphonesimulator/FBSnapshotTestCaseDemoTests.build/FBSnapshotTestCaseDemoTests-project-headers.hmap -I/Users/ramzes/Library/Developer/Xcode/DerivedData/FBSnapshotTestCaseDemo-crephtwyyhgsmsevtxsznsqmwhmy/Build/Products/Debug-iphonesimulator/include -I/Applications/Xcode6-Beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include -I/Users/ramzes/Library/Developer/Xcode/DerivedData/FBSnapshotTestCaseDemo-crephtwyyhgsmsevtxsznsqmwhmy/Build/Intermediates/FBSnapshotTestCaseDemo.build/Debug-iphonesimulator/FBSnapshotTestCaseDemoTests.build/DerivedSources/i386 -I/Users/ramzes/Library/Developer/Xcode/DerivedData/FBSnapshotTestCaseDemo-crephtwyyhgsmsevtxsznsqmwhmy/Build/Intermediates/FBSnapshotTestCaseDemo.build/Debug-iphonesimulator/FBSnapshotTestCaseDemoTests.build/DerivedSources -F/Users/ramzes/Library/Developer/Xcode/DerivedData/FBSnapshotTestCaseDemo-crephtwyyhgsmsevtxsznsqmwhmy/Build/Products/Debug-iphonesimulator -F/Applications/Xcode6-Beta.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator8.0.sdk/Developer/Library/Frameworks -F/Applications/Xcode6-Beta.app/Contents/Developer/Library/Frameworks -F/Applications/Xcode6-Beta.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/Library/Frameworks -F/Applications/Xcode6-Beta.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator8.0.sdk/Developer/Library/Frameworks -include /Users/ramzes/Library/Developer/Xcode/DerivedData/FBSnapshotTestCaseDemo-crephtwyyhgsmsevtxsznsqmwhmy/Build/Intermediates/PrecompiledHeaders/FBSnapshotTestCaseDemo-Prefix-eiqycqzcxnnyepeuurnkprvhkkwp/FBSnapshotTestCaseDemo-Prefix.pch -MMD -MT dependencies -MF /Users/ramzes/Library/Developer/Xcode/DerivedData/FBSnapshotTestCaseDemo-crephtwyyhgsmsevtxsznsqmwhmy/Build/Intermediates/FBSnapshotTestCaseDemo.build/Debug-iphonesimulator/FBSnapshotTestCaseDemoTests.build/Objects-normal/i386/FBSnapshotTestCase.d --serialize-diagnostics /Users/ramzes/Library/Developer/Xcode/DerivedData/FBSnapshotTestCaseDemo-crephtwyyhgsmsevtxsznsqmwhmy/Build/Intermediates/FBSnapshotTestCaseDemo.build/Debug-iphonesimulator/FBSnapshotTestCaseDemoTests.build/Objects-normal/i386/FBSnapshotTestCase.dia -c /Users/ramzes/Downloads/ios-snapshot-test-case/FBSnapshotTestCase.m -o /Users/ramzes/Library/Developer/Xcode/DerivedData/FBSnapshotTestCaseDemo-crephtwyyhgsmsevtxsznsqmwhmy/Build/Intermediates/FBSnapshotTestCaseDemo.build/Debug-iphonesimulator/FBSnapshotTestCaseDemoTests.build/Objects-normal/i386/FBSnapshotTestCase.o
/Users/ramzes/Downloads/ios-snapshot-test-case/FBSnapshotTestCase.m:77:65: error: property 'selector' not found on object of type 'FBSnapshotTestCase *'
selector:self.selector
^
1 error generated.
We put normal tests and snapshot tests in the same test bundle.
When I select to run a single unit test by clicking on the diamond in front of the line number of a specific test, somehow all existing snapshot tests are run.
This doesn't happen if I select a snapshot test.
Since FBSnapshotTestCase derive from XCTestCase, I can't understand why this is happening, but it's kind of annoying since it usually takes very long to run all snapshot tests compared to unit tests.
Any idea why this is happening?
For those of us using specta, it could be interesting to be able to write FBSnapshotTestCase
tests as follows:
SpecBegin(FooView)
__block FooView * view;
beforeEach(^{
_view = [[FooView alloc] initWithFrame:CGRectMake(0, 0, 300, 46)];
});
it(@"renders button", ^{
expect(_view).to.haveMatchingSnapshot();
});
SpecEnd
To make this happen I think we need to refactor FBSnapshotTestCase
a bit and add Specta matches.
What do you think?
Hi,
since 2.0 the compare doesn't work here anymore.
I assume that the change in UIImage+Diff.m
causes the problem.
Why is the following code removed?
CGFloat scaleFactor = [[UIScreen mainScreen] scale];
CGContextScaleCTM(referenceImageContext, scaleFactor, scaleFactor);
CGContextScaleCTM(imageContext, scaleFactor, scaleFactor);
Without this it doesn't work here anymore.
Check out https://github.com/aleph7/AIImageCompare, it supports mean image comparison where you don't have to have exactly identical images. This may be useful for cases where there're, say, anti-aliasing marginal errors in image comparison.
It would be awesome if running on device worked, I get error that the reference image doesn't exist because it is trying to access the image on the Mac.
Do you think it would be possible to bundle the reference images into the test target so that running on device would work?
It seems like the folder where reference images are stored changed between 1.7 and 1.8.
All of my snapshot tests fail unless I rename my reference image folder from ReferenceImages
to ReferenceImages_64
Using Cocoapods, pointing at ~> 2.0.5
, the module will no longer build for me with the error /Pods/FBSnapshotTestCase/FBSnapshotTestCase/FBSnapshotTestCase.h:11:9: Include of non-modular header inside framework module 'FBSnapshotTestCase.FBSnapshotTestCase'
.
It's complaining because FBSnapshotTestCase.h
imports the non-modular header FBSnapshotTestCasePlatform.h
. I'll look into this when I get time but if someone else can help that'd be great!
I'm new to version 2 of ios-snapshot-test-case so please forgive me if I've misunderstood how the suffixes are intended to work.
I've created a simple test which renders one of my custom UIView objects with a frame of size (50,50). I run the test on the iPhone 6 simulator with recordMode
set to YES
and it creates the expected reference image in the ReferenceImages_64
directory.
When I set recordMode
to NO
and change an attribute of the view, such as the frame, the test fails with the following error: Reference image not found. You need to run the test in record mode
The reason it fails because there is an error matching against the snapshot in ReferenceImages_64
(which exists), and so it continues with the next suffix (_32
) and the final error returned is that a reference image does not exist in ReferenceImages_32
.
Of course, if I force a set of suffixes with a single suffix string, my tests work as expected and I get the correct error message, NSLocalizedFailureReason=referenceImage:{50, 50}, image:{150, 50}}
.
I would expect the error returned to be the first error encountered which is not an instance of FBSnapshotTestControllerErrorCodeNeedsRecord
.
It seems to me that the macro loop here should check the error code and break for the different size/different image cases.
Let me know if I can help with a PR for this or please point out where I'm going wrong.
Hey *,
I am wondering if / how it is possible to test a view in different Size Classes as we different constants and even constraints.
#26 was closed, opening this one to make sure it's not forgotten.
It seems possible to get different images between different runs. It seems like "running the first time" on a new machine will produce a failure, then recording a new snapshot creates a byte-identical image, then running the test again succeeds. I've tried all kinds of things to get a handle on this one, #19 does not fix the problem.
Here're images from the first failure.
If you look very carefully, the diff has some issues around the text antialiasing, but I've witnessed the same problem where there're two UIImageView's overlaying each other, one being the background of the other, The resulting difference is a very thin blend of the background image.
I get the following error on some of our view tests with Xcode 7 and iOS 9:
/App/Pods/FBSnapshotTestCase/FBSnapshotTestCase/Categories/UIImage+Snapshot.m:26: error: -[SomeTestViewControllerTests testMethod] : failed: caught "CALayerInvalidGeometry", "sublayer with non-finite position [inf inf]"
(
0 CoreFoundation 0x0612fa94 __exceptionPreprocess + 180
1 libobjc.A.dylib 0x05b23e02 objc_exception_throw + 50
2 CoreFoundation 0x0612f9bd +[NSException raise:format:] + 141
3 QuartzCore 0x039fd4e6 -[CALayer _renderSublayersInContext:] + 546
4 QuartzCore 0x039fba02 -[CALayer renderInContext:] + 1166
5 QuartzCore 0x039fd4e6 -[CALayer _renderSublayersInContext:] + 546
6 QuartzCore 0x039fba02 -[CALayer renderInContext:] + 1166
7 QuartzCore 0x039fd4e6 -[CALayer _renderSublayersInContext:] + 546
8 QuartzCore 0x039fba02 -[CALayer renderInContext:] + 1166
9 QuartzCore 0x039fd4e6 -[CALayer _renderSublayersInContext:] + 546
10 QuartzCore 0x039fba02 -[CALayer renderInContext:] + 1166
11 QuartzCore 0x039fd4e6 -[CALayer _renderSublayersInContext:] + 546
12 QuartzCore 0x039fba02 -[CALayer renderInContext:] + 1166
13 QuartzCore 0x039fd4e6 -[CALayer _renderSublayersInContext:] + 546
14 QuartzCore 0x039fba02 -[CALayer renderInContext:] + 1166
15 QuartzCore 0x039fd4e6 -[CALayer _renderSublayersInContext:] + 546
16 QuartzCore 0x039fba02 -[CALayer renderInContext:] + 1166
17 AutoScout24Tests 0x14c861ad +[UIImage(Snapshot) fb_imageForLayer:] + 1325
18 AutoScout24Tests 0x14c862d3 +[UIImage(Snapshot) fb_imageForViewLayer:] + 147
19 AutoScout24Tests 0x14c8477d -[FBSnapshotTestController _imageForViewOrLayer:] + 237
20 AutoScout24Tests 0x14c84063 -[FBSnapshotTestController _performPixelComparisonWithViewOrLayer:selector:identifier:tolerance:error:] + 243
21 AutoScout24Tests 0x14c82b50 -[FBSnapshotTestController compareSnapshotOfViewOrLayer:selector:identifier:tolerance:error:] + 304
22 AutoScout24Tests 0x14c824a4 -[FBSnapshotTestCase _compareSnapshotOfViewOrLayer:referenceImagesDirectory:identifier:tolerance:error:] + 340
23 AutoScout24Tests 0x14c820c0 -[FBSnapshotTestCase compareSnapshotOfView:referenceImagesDirectory:identifier:tolerance:error:] + 224
24 AutoScout24Tests 0x148f43d4 -[SomeTestViewControllerTests testMethod] + 1316
25 CoreFoundation 0x06007ccd __invoking___ + 29
26 CoreFoundation 0x06007b76 -[NSInvocation invoke] + 342
27 XCTest 0x125ccd34 __24-[XCTestCase invokeTest]_block_invoke_2 + 174
28 XCTest 0x1260520f -[XCTestContext performInScope:] + 229
29 XCTest 0x125ccc79 -[XCTestCase invokeTest] + 193
30 XCTest 0x125cd233 -[XCTestCase performTest:] + 529
31 XCTest 0x125f743a -[XCTest runTest] + 354
32 XCTest 0x125ca8d2 -[XCTestSuite performTest:] + 427
33 XCTest 0x125f743a -[XCTest runTest] + 354
34 XCTest 0x125ca8d2 -[XCTestSuite performTest:] + 427
35 XCTest 0x125f743a -[XCTest runTest] + 354
36 XCTest 0x125b43c4 __25-[XCTestDriver _runSuite]_block_invoke + 61
37 XCTest 0x125db046 -[XCTestObservationCenter _observeTestExecutionForBlock:] + 736
38 XCTest 0x125b42e9 -[XCTestDriver _runSuite] + 491
39 XCTest 0x125b5364 -[XCTestDriver _checkForTestManager] + 318
40 XCTest 0x125b5839 -[XCTestDriver runTestConfiguration:completionHandler:] + 399
41 XCTest 0x126068df _XCTestMain + 715
42 IDEBundleInjection 0x0140b5eb ____XCBundleInjection_block_invoke_2 + 20
43 CoreFoundation 0x06049e60 __CFRUNLOOP_IS_CALLING_OUT_TO_A_BLOCK__ + 16
44 CoreFoundation 0x0603f7e3 __CFRunLoopDoBlocks + 195
45 CoreFoundation 0x0603ef18 __CFRunLoopRun + 1016
46 CoreFoundation 0x0603e866 CFRunLoopRunSpecific + 470
47 CoreFoundation 0x0603e67b CFRunLoopRunInMode + 123
48 GraphicsServices 0x0830e664 GSEventRunModal + 192
49 GraphicsServices 0x0830e4a1 GSEventRun + 104
50 UIKit 0x03d38cc1 UIApplicationMain + 160
51 AutoScout24 0x000f202a main + 138
52 libdyld.dylib 0x06f1ba21 start + 1
)
Test Case '-[SomeTestViewControllerTests testMethod]' failed (26.960 seconds).
Test Suite 'SomeTestViewControllerTests' failed at 2015-09-11 13:59:47.126.
Executed 1 test, with 1 failure (1 unexpected) in 26.960 (26.963) seconds
Test Suite 'Selected tests' failed at 2015-09-11 13:59:47.126.
Executed 1 test, with 1 failure (1 unexpected) in 26.960 (26.965) seconds
Any idea what happens there?
64-bit runs often render text slightly different, causing snapshot failures if run on the wrong device.
I think https://github.com/facebook/ios-snapshot-test-case/blob/master/FBSnapshotTestCase.podspec#L24 doesn't do anything useful. It literally sets the value to "$(SOURCE_ROOT)/$(PROJECT_NAME)Tests/ReferenceImages" (doesn't resolve SOURCE_ROOT for example. It also sets that on the Pod project, you want it on the test project so that the macros can pick it up.
Am I missing something?
It would seem that we have been relying on the drawViewHierarchyInRect:afterScreenUpdates: that was called before being removed in #63.
The specific issue is that a view is marked and not installed in the storyboard for some size classes but is still appearing is now appearing.
The work around we are currently using through lack of a better alternative is to just call:
[subject.view drawViewHierarchyInRect:subject.view.frame afterScreenUpdates:TRUE];
before our expectation.
This is obviously not ideal. Does anyone know what this is actually doing under the hood or have any better suggestions to fix this issue?
It would be nice that instead of having to provide our own identifier it could infer it from the class or function name instead.
Hey all. I'm having a really weird, intermittent problem when I try and snapshot a view belonging to a controller that's been loaded from a Storyboard in iOS 8. Lots of details of what I've tried so far are here, but the gist of it is that the image rendered from drawViewHierarchyInRect
is empty โ the correct size, but transparent.
Has anyone else seen this?
The library gained support for built-in image diffing and Expecta support. Now community needs new version published at CocoaPods. I simply can't do this since only owners could update the spec. Could you please do this?
I checked build settings of repo on travis, and I see that CI runs test only on iPhone 6, so only 64bit architecture.
I think CI should test also 32 bit architecture (eg. iPhone 5).
Due to the use of macros, it is difficult to use FBSnapshotTestCase
with Swift. Information is fairly scarce on getting it to work but it looks like this StackOverflow answer might be an elegant solution.
The snapshot render the UI without rendering view with the setup of their UIApperances selector.
According to the 2011 WWDC video introducing UIAppearance, the customizations are applied right before -layoutSubviews is called on the view.
Instead of defining a custom macro to map reference dirs, allow installation of a reference image mapper function on FBSnapshotVerifyView. Default behavior is no map (i.e. no suffix).
See #65 for context
In FBSnapshotTestController.h, its docblock contains parameters copied from -compareSnapshotOfView which don't match its actual parameters.
Seems like FBTestSnapshotController
vs FBSnapshotTestCase
are inconsistent. I'm adding a third class in #8, and wondering whether I should add FBTestSnapshotRecorder
or FBSnapshotTestRecorder
.
We'd like to test AsyncDisplayNode with snapshots.
At the very least, testing by synchronously forcing view/layer display should be workable?
Hi,
has anybody a good idea to skip tests on other devices?
So if i make an view test on an iPhone i'd like to skip it on iPad.
I could do a if clause before the assert, but then Xcode runs the tests and only skip the assert.
Any idea?
I made a plain unit test project, starting from an Empty XCode project and adding a "Cocoa Touch Unit Testing Bundle" target.
There's a warning there about "unknown device type", it looks related.
Drawing a view crashes as follows:
2014-03-25 18:25:06.616 xctest[57029:303] Unknown Device Type. Using UIUserInterfaceIdiomPhone based on screen size
<unknown>:0: error: -[UIImageViewASCIISpec no] : *** -[__NSArrayM objectAtIndex:]: index 0 beyond bounds for empty array
(
0 CoreFoundation 0x00b251e4 __exceptionPreprocess + 180
1 libobjc.A.dylib 0x007988e5 objc_exception_throw + 44
2 CoreFoundation 0x00ac63f6 -[__NSArrayM objectAtIndex:] + 246
3 UIKit 0x06748a7b +[_UIReplicantView _pendingSnapshotOfTarget:snapshotBlock:] + 229
4 UIKit 0x067302f6 -[UIView drawViewHierarchyInRect:afterScreenUpdates:] + 282
5 Tests 0x02f31161 -[FBSnapshotTestController _renderView:] + 449
6 Tests 0x02f30cb2 -[FBSnapshotTestController _snapshotViewOrLayer:] + 162
7 Tests 0x02f30b49 -[FBSnapshotTestController _recordSnapshotOfViewOrLayer:selector:identifier:error:] + 153
8 Tests 0x02f3080e -[FBSnapshotTestController compareSnapshotOfViewOrLayer:selector:identifier:error:] + 206
9 Tests 0x02f08f0a +[EXPExpectFBSnapshotTest compareSnapshotOfViewOrLayer:snapshot:testCase:record:referenceDirectory:error:] + 554
10 Tests 0x02f0eaad __60-[EXPExpect(recordSnapshotNamedMatcher) recordSnapshotNamed]_block_invoke_7 + 269
11 Tests 0x02f0f4b2 -[EXPBlockDefinedMatcher matches:] + 98
12 Tests 0x02f10699 -[EXPExpect applyMatcher:to:] + 905
13 Tests 0x02f0e8ee __60-[EXPExpect(recordSnapshotNamedMatcher) recordSnapshotNamed]_block_invoke_5 + 1038
14 Tests 0x02f025e3 __38-[UIImageViewASCIISpec spt_defineSpec]_block_invoke_2 + 595
15 Tests 0x02f351ec runExampleBlock + 1500
16 Tests 0x02f36832 __48-[SPTExampleGroup compileExamplesWithNameStack:]_block_invoke + 258
17 Tests 0x02f3bbbc -[SPTXCTestCase spt_runExampleAtIndex:] + 556
18 CoreFoundation 0x00b1991d __invoking___ + 29
19 CoreFoundation 0x00b1982a -[NSInvocation invoke] + 362
20 XCTest 0x20103c6c -[XCTestCase invokeTest] + 221
21 XCTest 0x20103d7b -[XCTestCase performTest:] + 111
22 Tests 0x02f3c5a8 -[SPTXCTestCase performTest:] + 152
23 XCTest 0x20104c48 -[XCTest run] + 82
24 XCTest 0x201033e8 -[XCTestSuite performTest:] + 139
25 XCTest 0x20104c48 -[XCTest run] + 82
26 XCTest 0x201033e8 -[XCTestSuite performTest:] + 139
27 XCTest 0x20104c48 -[XCTest run] + 82
28 XCTest 0x201033e8 -[XCTestSuite performTest:] + 139
29 XCTest 0x20104c48 -[XCTest run] + 82
30 XCTest 0x201066ba +[XCTestProbe runTests:] + 183
31 libobjc.A.dylib 0x007aa743 +[NSObject performSelector:withObject:] + 70
32 xctest 0x0000233e xctest + 4926
33 xctest 0x00002590 xctest + 5520
34 xctest 0x00002671 xctest + 5745
35 xctest 0x00002007 xctest + 4103
36 libdyld.dylib 0x01679701 start + 1
37 ??? 0x00000008 0x0 + 8
Repro in https://github.com/dblock/ARASCIISwizzle/tree/project-reorg-top-level, Tests project.
I've noticed that reference images recorded when tests were running on iOS7 are not the same when running on iOS8. Looks like there are some updates in UIKit which result in different rendering. For example on the screenshot below there is screenshot recorded on iOS7 on the left and on iOS8 on the right. Note that accessory indicator on iOS8 has less padding on the right.
Have anybody else experiencing similar problems?
If you run unit tests again one iOS version you will be probably fine, but I'm curious what others do to be able to run unit tests on different iOS versions? Thanks in advance!
In some cases you have a snapshot using a simulator of a different size. Instead of just reporting that the snapshot doesn't match, report that the sizes don't match (with the sizes included in the error).
It took me a while to figure out that the simulator running on Travis-CI was a 4'' one for example (no idea why that's the default, btw).
Hi there! Congrats on the 1.7 release. Could you push it to CocoaPods trunk when you get a chance? Thanks!
This should be useful for debugging, especially when using some tolerance level.
Is this possible to achieve? Some of the tests I'm running depend of the system keyboard to be displayed as well. I've tried many things, without success.
Since Xcode 6 / iOS 8 there is a major bug in the compare of two images:
If you have a UIView
ASCTransparentView *view = [[ASCTransparentView alloc] initWithFrame:CGRectMake(0, 0, 10, 10)];
view.backgroundColor = [UIColor clearColor];
FBSnapshotVerifyView(view, nil);
with a drawRect:
method
- (void)drawRect:(CGRect)rect
{
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetStrokeColorSpace(context, CGColorGetColorSpace([UIColor lightGrayColor].CGColor));
CGContextSetStrokeColor (context, CGColorGetComponents([UIColor lightGrayColor].CGColor));
CGContextStrokeEllipseInRect (context, CGRectMake(self.bounds.size.width - 9, self.bounds.size.height - 9, 8, 8));
}
and view.backgroundColor = [UIColor clearColor];
compare always fails.
If you use [UIColor greenColor]
instead of [UIColor lightGrayColor]
for stroke it also works!
So every color that has a other value then 1.0
or 0.0
for any rgb value fails.
If you compare it with Xcode 5 / iOS 7 it works fine.
I made a example project which shows this issue:
https://github.com/x2on/FBSnapshotTestXcode6ExampleWithClearColor
Any idea what happens here?
I made a test and recored the image with the following code:
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0,0,50,50)];
view.backgroundColor = [UIColor whiteColor];
FBSnapshotVerifyView(view, nil);
Then i changed it to the following code:
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0,0,50,50)];
view.backgroundColor = [UIColor whiteColor];
UILabel *testLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 50, 50)];
testLabel.text = @"TEST";
testLabel.textColor = [UIColor blueColor];
[view addSubview:testLabel];
FBSnapshotVerifyView(view, nil);
When i rerun the test it succeeded instead of failing.
In the
- (BOOL)compareReferenceImage:(UIImage *)referenceImage toImage:(UIImage *)image error:(NSError **)errorPtr
i used quicklook and the label is in the image
, but the compare algorithm doesn't fail.
I'm trying to find a work around, but for the time being, I wanted to reach out here and see if there's a way to utilize FBSnapshotTestCase with views that use Auto Layout for layout and positioning of its contents. Currently the contents are completely empty when a snapshot is taken.
I wrote a Stack Overflow question here with more details, but I'm having trouble getting FBSnapshotTestCase
tests to pass on CircleCI (they pass locally). FBSnapshotTestCase
is using the _32
directory for some reason, even though I'm specifying a 64-bit simulator in the circle.yml
file.
Is this related to #102? Are there known incompatibilities between FBSnapshotTestCase
and CircleCI? Any other ideas? (Or feel free to post on the SO question.)
Hi there! I had a commit merged in about two months ago, and I'd like to rely on that commit for a CocoaPod that I'm building. Could someone tag a release on or after that tag (say, 1.4.1 or something)? Then we can update the podspec to point to that new tag and @dstnbrkr can pod trunk push
the new version to CocoaPods.
Most of these don't match up to their arguments: https://github.com/facebook/ios-snapshot-test-case/blob/master/FBSnapshotTestController.h#L43-L147
The snapshot being taken is always portrait. This is incorrect when the device is forced into landscape orientation, for example. I've modified the demo app in https://github.com/dblock/ios-snapshot-test-case/tree/orientation-issues to display a rectangle in the middle of the screen.
In landscape, it should look like this:
However, the snapshot taken looks like this:
Note that the snapshot is wrong, it's not just rotated by 90 degrees.
This SO may be a beginning of an answer, but I couldn't get it to work.
I assume theres no way to use FBSnapshotTestCase
with WKInterfaceController
s from WatchKit? I'm pretty certain theres no way to render a WKInterfaceController
outside of the simulator but I may be missing something.
I'm trying to create reference images for views of my view controller for different devices so that I can test the screenshot of my views later.
I'm trying do something like this
func testLoginViewController() {
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let navViewController = storyboard.instantiateInitialViewController()
let viewController = navViewController.topViewController as! LoginViewController
FBSnapshotVerifyView(viewController.view)
}
I can successfully create the reference images but all the images have the size of 640x960 although I run different simulators (iPhone 4s -> iPhone 6 Plus).
Does anyone know where the problem is?
Hi,
now that the Xcode 6 GM is out the door, it would be really cool if you could cut a new release. People will start switching to Xcode 6 soon, I guess. Then they'll run into the bug that has been fixed in c405587.
What do you think?
Thanks,
plu
I am not sure what the deal is, but a view with custom drawing is not screen-shotted properly. There's a test in https://github.com/dblock/NAMapKit/blob/tiled-map-view/Demo/DemoTests/NATiledImageMapViewControllerTests.m#L24 that reproduces this.
Looks like an issue with FB_REFERENCE_IMAGE_DIR. I thought there was an issue on my end in my project but it looks like the demo project doesn't work (with the latest version of CocoaPods).
2015-05-17 22:43:57.424 FBSnapshotTestCaseDemo[14107:6951453] Application windows are expected to have a root view controller at the end of application launch
Test Suite 'All tests' started at 2015-05-18 02:43:57 +0000
Test Suite 'FBSnapshotTestCaseDemoTests.xctest' started at 2015-05-18 02:43:57 +0000
Test Suite 'FBSnapshotTestCaseDemoTests' started at 2015-05-18 02:43:57 +0000
Test Case '-[FBSnapshotTestCaseDemoTests testExample]' started.
/Users/stevemoser/Downloads/ios-snapshot-test-case-master/FBSnapshotTestCaseDemo/FBSnapshotTestCaseDemoTests/FBSnapshotTestCaseDemoTests.m:32: error: -[FBSnapshotTestCaseDemoTests testExample] : ((comparisonSuccess__) is true) failed - Snapshot comparison failed: Error Domain=FBSnapshotTestControllerErrorDomain Code=1 "Unable to load reference image." UserInfo=0x7f858842ede0 {NSLocalizedFailureReason=Reference image not found. You need to run the test in record mode, NSLocalizedDescription=Unable to load reference image., FBReferenceImageFilePathKey="$(SOURCE_ROOT)/$(PROJECT_NAME)Tests/ReferenceImages"_32/FBSnapshotTestCaseDemoTests/[email protected]}
Test Case '-[FBSnapshotTestCaseDemoTests testExample]' failed (0.002 seconds).
Test Suite 'FBSnapshotTestCaseDemoTests' failed at 2015-05-18 02:43:57 +0000.
Executed 1 test, with 1 failure (0 unexpected) in 0.002 (0.005) seconds
Test Suite 'FBSnapshotTestCaseDemoTests.xctest' failed at 2015-05-18 02:43:57 +0000.
Executed 1 test, with 1 failure (0 unexpected) in 0.002 (0.005) seconds
Test Suite 'All tests' failed at 2015-05-18 02:43:57 +0000.
Executed 1 test, with 1 failure (0 unexpected) in 0.002 (0.006) seconds
I'm not sure what is causing this or if it would be fixed by #19.
For some of our snapshot tests, if we record them on the 32 bit simulator and then immediately run it back in the 64 bit simulator, it results in a test failure - but there's no visible difference in the images. Same if we record in 64 bit and test in 32 bit. This doesn't happen for every image, but for the images it does fail, it is consisten.
As a result, our Xcode bot reports failures for the other architecture.
Any ideas what would be causing this or how I could address this?
Since release 1.2 and the changes with drawViewHierarchyInRect:afterScreenUpdates
most of our tests are failing. Release 1.2 is not usable for us.
Why is drawViewHierarchyInRect:afterScreenUpdates
necessary? Performance?
If your view has a UIVisualEffectView
, then the snapshot is rendered without a blur effect. The root of this problem is that you need to wait for view updates before taking the snapshot. This is closely tied to the removal of drawViewHierarchyInRect:afterScreenUpdates in #52
Adding in the wait for screen update fixes the snapshot's blur, while breaking the auto layout.
Is there a way to delay capturing the snapshot for an arbitrary amount of time?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.