Appcircle helps you perform unit and UI tests for your iOS applications at once.
Unit tests usually test a piece of your code and confirm the code behaves as expected in certain conditions.
Unit tests are created in Xcode using the XCTest framework. Test methods are stored in XCTestCase
subclass.
You can create unit tests in Xcode using the Test Navigator. Open the Test Navigator and click on the + icon in the lower left corner. Select New Unit Test Target. You should see the bundle and the XCTestCase
subclass created.
You can now use XCTAssert functions to test your models or other assets.
To run your tests during the build process, you can simply use a custom script in your build profile.
Simply go to your build workflow and add a custom script after the Xcode Select step so that tests will be run before the actual build starts.
See the following page on our documentation to learn more about creating custom workflow steps:
We will use a Ruby script here to tell Appcircle to run our unit and UI tests.
# Instal dependenciesrequire 'open3'require 'pathname'​# Check & validate Enviroment Variablesdef env_has_key(key)return (ENV[key] != nil && ENV[key] !="") ? ENV[key] : abort("Missing #{key}.")end​$project_path = ENV["AC_PROJECT"] || abort('Missing project path.')$repository_path = ENV["AC_REPOSITORY_DIR"]$project_full_path = $repository_path ? (Pathname.new $repository_path).join($project_path) : $project_path$scheme = env_has_key("AC_SCHEME")$output_path = env_has_key("AC_OUTPUT_DIR")$test_result_path = "#{$output_path}/test.xcresult"​# Create a function to run test commandsdef run_command(command, skip_abort)puts "@[command] #{command}"status = nilstdout_str = nilstderr_str = nilOpen3.popen3(command) do |stdin, stdout, stderr, wait_thr|stdout.each_line do |line|puts lineendstdout_str = stdout.readstderr_str = stderr.readstatus = wait_thr.valueendunless status.success?puts stderr_strunless skip_abortexit 1endendend​# Command to tell Xcode to run tests with parameterscommand_xcodebuild_test = "xcodebuild -project #{$project_full_path} -scheme #{$scheme} -destination 'platform=iOS Simulator,name=iPhone 11,OS=latest' -resultBundlePath #{$test_result_path} test COMPILER_INDEX_STORE_ENABLE=NO"​# Run our function and perform the testsrun_command(command_xcodebuild_test,false)​exit 0
Unit & UI test results will be packed along with the .ipa
file generated after the build if you also sign your artifact using your provisioning profile. You can download test results in the same .zip
archive and you will see the test.xcresult.zip
file that includes test data.
If you don't sign your build artifact, your test results will be included in the xcarchive
file. You can alternatively disable your build and sign steps in your workflow and get only test results without building or signing your application.
You can use 3rd party tools like 🔗 XCParse or 🔗 XCTestHTMLReport to view your test results in more user-friendly way.