Create tests
AppCode provides templates for creating unit and UI tests based on the XCTest framework. When creating a new project in AppCode, you can select if you want unit and UI tests to be added. In this case, AppCode creates test targets containing test classes with initial content. However, you can add test targets and test classes anytime after a project is created.
To quickly add stub code for methods in test classes, use the Generate menu⌘ N. This functionality is available for Objective-C only.
See examples of XCTest and Quick tests in the Unit testing in AppCode tutorial.
Add a test target
Open the project settings by pressing ⌃ ⌥ ⇧ S or selecting from the main menu.
Click and select a test target from the dialog that opens.
Select iOS UI Testing Bundle to create a target for UI tests or iOS Unit Testing Bundle — for unit tests. Click Next.
On the next page, if necessary, change the values in the following fields:
Product Name: the name of the new test target.
Organization Name: the name of your company or your name.
Language: the programming language for the test classes within the target.
Project: the project where the new target will be created.
Target to be Tested: the target that will be tested.
A new test target will be added to the project. This target contains a test class with stub code for several test methods that you can fill in.
Add a test class
In the Project tool window, right-click the group you want to add a test class to and select .
Select the Source file type from the left pane and UI Test Case Class or Unit Test Case Class from the right pane. Click Next.
On the next page, if necessary, change the values in the following fields:
File name: the name of the new test class.
Location: the directory in the file system where the new file will be created.
Subclass of: the parent class for the class that is being created. By default, XCTestCase.
Language: the programming language the class will be written in.
Group: the group in the AppCode project the class will belong to.
Target: the list of targets where the class will be added.
Generate code for tests
To generate code for test methods, place the caret within the test class code, press ⌘ N, and select the desired action from the menu that opens. This functionality is available for Objective-C only.
Depending on the testing framework you use, different code templates can be generated:
XCTest and Google Test:
SetUp
,TearDown
, andTest
methods:For Google Test, AppCode also offers you a variety of
TEST
macros:TEST()
TEST_F()
TEST_P()
TYPED_TEST()
TYPED_TEST_P()
You can generate a
TEST()
macro, and after you specify a suite name, AppCode will change this macro to the correct one automatically.Kiwi:
it
,context
,beforeEach
,afterEach
, andspecify
blocks: