uber / ios-snapshot-test-case

Snapshot view unit tests for iOS
MIT License
1.79k stars 214 forks source link

Can't generate image folder set in FB_REFERENCE_IMAGE_DIR #130

Open williamhqs opened 4 years ago

williamhqs commented 4 years ago
I followed the set the Environment Variables like below: FB_REFERENCE_IMAGE_DIR $(SOURCE_ROOT)/$(PROJECT_NAME)Tests/ReferenceImages
IMAGE_DIFF_DIR $(SOURCE_ROOT)/$(PROJECT_NAME)Tests/FailureDiffs

but I can't find the folders ReferenceImages and FailureDiffs.

I can only find it from the log:

/Users/william/Library/Developer/Xcode/DerivedData/MyProject-gpgfmvvbgxrsaqamedlklzlbhyxu/Build/Products/Test-iphonesimulator/MyProject.app/PlugIns/MyProject Tests.xctest/ReferenceImages_64/MyProject Tests.CountdownViewTests/testExampleAndReturnError:@2x.png

I also tried set a fixed path, still doesn't work. Not sure the reason why, I don't want to find it from the console every time.

Any help? Thanks!

ekranac commented 4 years ago

Same here. I've also taken a look at getReferenceImageDirectoryWithDefault method and found that none of the defined environment variables gets passed upon running.

ekranac commented 4 years ago

If you are using test plans, this might be of help to you.

Since I've recently converted to test plans, I was defining the environment variables the wrong way. I've opened a pull request (#131) with updated instructions. Basically, you need to set the variables inside the test plans configuration, not the run action section of your scheme because they will not get automatically transferred to the test action as they did before.

rfodge commented 3 years ago

One additional note wrt @ekranac comment above, in addition to setting the environment variables for the configuration, I had to pick the scheme in the 'Target for Variable Expansion' setting

dennismozart1994 commented 3 years ago

I'm having the same issue... Even if I set the values on test plans or branch new schemes, the code fails to create the directory at _saveReferenceImage function under FBSnapshotTestController.m.

When calling the [_fileManager createDirectoryAtPath:[filePath stringByDeletingLastPathComponent] withIntermediateDirectories:YES attributes:nil error:&creationError]; it returns the following error:

Error Domain=NSCocoaErrorDomain Code=4 "The file “MyTestScheme.MyTestClass” doesn’t exist." UserInfo={NSFilePath=/Users/MyUser/MyProjectName/MyTestScheme/ReferenceImages_64/MyTestScheme.MyTestClass, NSUnderlyingError=0x600003b45e60 {Error Domain=NSPOSIXErrorDomain Code=2 "No such file or directory"}}