Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

XCode Unit Tests - Cannot find viewcontroller in scope

At some point in my app's development, my Unit Tests and UI Tests lost access to my app's main module:

🛑 Cannot find type 'FileVacuumViewController' in scope

Cannot find type 'FileVacuumViewController' in scope

They worked with the xctestplan before. I don't know at what point it happened. I tried not importing @testable, including the tests.swift in the main module's "Target Membership".

Maybe I need to open the workspace instead of the xcproject? When I try to open the workspace there was an error message and no files show in the tree: enter image description here


Here's my xctestplan config:

xctestplan config

When I clicked to run one the UI tests individually, about 20 of these code sign dialogs showed:

code sign popups

like image 443
Mikeumus Avatar asked Sep 22 '20 13:09

Mikeumus


3 Answers

Looks like your test file is included in both your app target and test bundle. Make sure to uncheck it from app target and try clean & build.

like image 132
manman Avatar answered Nov 07 '22 10:11

manman


Select file "FileVacuumViewController" in Project Navigator and, in File Inspector, in the section Target Membership, check field which ends with Tests and UITests. Clean and build project, if necessary.

like image 27
Vladimir Sukanica Avatar answered Nov 07 '22 11:11

Vladimir Sukanica


I ran into this recently with XCode 13 while following a blog post on creating unit tests. For some reason, XCode didn't automatically add the ViewController to the Test target.

My solution was to make sure that the ViewController was included in the Target Membership for the test suite. I had to also make the same Target Membership change for the Main storyboard.

Screenshot of selected checkbox for the project's tests in the Target Membership section of XCode while the View Controller is selected in the Files pane

like image 3
Aaron Breckenridge Avatar answered Nov 07 '22 10:11

Aaron Breckenridge