Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to force xcodebuild to test #49

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions test_runner/ios_test_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,12 @@ def _AddGeneralArguments(parser):
'2) the screenshots of every test stages (XCUITest).\n'
'If directory is specified, the directory will not be deleted after '
'test ends.')
optional_arguments.add_argument(
'--force_xcodebuild',
help='Forces the use of xcodebuild, specifically for use within logic test. '
'Defaults to False.',
action='store_true')



def _AddPrepareSubParser(subparsers):
Expand All @@ -111,7 +117,8 @@ def _Prepare(args):
sdk=sdk,
device_arch=device_arch,
work_dir=args.work_dir,
output_dir=args.output_dir) as session:
output_dir=args.output_dir,
force_xcodebuild=args.force_xcodebuild) as session:
session.Prepare(
app_under_test=args.app_under_test_path,
test_bundle=args.test_bundle_path,
Expand Down Expand Up @@ -147,7 +154,8 @@ def _Test(args):
sdk=sdk,
device_arch=device_arch,
work_dir=args.work_dir,
output_dir=args.output_dir) as session:
output_dir=args.output_dir,
force_xcodebuild=args.force_xcodebuild) as session:
session.Prepare(
app_under_test=args.app_under_test_path,
test_bundle=args.test_bundle_path,
Expand Down Expand Up @@ -182,7 +190,9 @@ def _RunSimulatorTest(args):
with xctest_session.XctestSession(
sdk=ios_constants.SDK.IPHONESIMULATOR,
device_arch=ios_constants.ARCH.X86_64,
work_dir=args.work_dir, output_dir=args.output_dir) as session:
work_dir=args.work_dir,
output_dir=args.output_dir,
force_xcodebuild=args.force_xcodebuild) as session:
simulator_id, _, os_version, _ = simulator_util.CreateNewSimulator(
device_type=args.device_type,
os_version=args.os_version,
Expand Down
17 changes: 11 additions & 6 deletions test_runner/xctest_session.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
class XctestSession(object):
"""The class that runs XCTEST based tests."""

def __init__(self, sdk, device_arch, work_dir=None, output_dir=None):
def __init__(self, sdk, device_arch, work_dir=None, output_dir=None, force_xcodebuild=False):
"""Initializes the XctestSession object.

If work_dir is not provdied, will create a temp direcotry to be work_dir and
Expand All @@ -54,6 +54,7 @@ def __init__(self, sdk, device_arch, work_dir=None, output_dir=None):
self._work_dir = work_dir
self._delete_work_dir = True
self._output_dir = output_dir
self._force_xcodebuild = force_xcodebuild
self._delete_output_dir = True
self._startup_timeout_sec = None
self._destination_timeout_sec = None
Expand Down Expand Up @@ -131,14 +132,15 @@ def Prepare(self, app_under_test=None, test_bundle=None,
self._work_dir, app_under_test, test_bundle)
test_type = _FinalizeTestType(
test_bundle_dir, self._sdk, app_under_test_dir=app_under_test_dir,
original_test_type=test_type)
original_test_type=test_type, force_xcodebuild=self._force_xcodebuild)

if test_type not in ios_constants.SUPPORTED_TEST_TYPES:
raise ios_errors.IllegalArgumentError(
'The test type %s is not supported. Supported test types are %s' %
(test_type, ios_constants.SUPPORTED_TEST_TYPES))

if test_type != ios_constants.TestType.LOGIC_TEST:
if test_type != ios_constants.TestType.LOGIC_TEST or (
test_type == ios_constants.TestType.LOGIC_TEST and self._force_xcodebuild):
xctestrun_factory = xctestrun.XctestRunFactory(
app_under_test_dir, test_bundle_dir, self._sdk, self._device_arch,
test_type, signing_options, self._work_dir)
Expand Down Expand Up @@ -321,7 +323,7 @@ def _PrepareBundles(working_dir, app_under_test_path, test_bundle_path):


def _FinalizeTestType(
test_bundle_dir, sdk, app_under_test_dir=None, original_test_type=None):
test_bundle_dir, sdk, app_under_test_dir=None, original_test_type=None, force_xcodebuild=False):
"""Finalizes the test type of the test session according to the args.

If original_test_type is not given, will auto detect the test bundle.
Expand Down Expand Up @@ -367,8 +369,11 @@ def _FinalizeTestType(
'app under test is not given.')
if (not app_under_test_dir and
test_type != ios_constants.TestType.LOGIC_TEST):
raise ios_errors.IllegalArgumentError(
'The app under test is required in test type %s.' % test_type)
if force_xcodebuild:
test_type = ios_constants.TestType.LOGIC_TEST
else:
raise ios_errors.IllegalArgumentError(
'The app under test is required in test type %s.' % test_type)
return test_type


Expand Down