Skip to content

Commit

Permalink
Fix ui test bundle not executing, added fixture test
Browse files Browse the repository at this point in the history
  • Loading branch information
ollieatkinson committed Mar 23, 2019
1 parent 9e14948 commit a57f2e6
Show file tree
Hide file tree
Showing 7 changed files with 88 additions and 8 deletions.
15 changes: 11 additions & 4 deletions Sources/TuistKit/Generator/ConfigGenerator.swift
Expand Up @@ -170,17 +170,24 @@ final class ConfigGenerator: ConfigGenerating {
settings["MACH_O_TYPE"] = "staticlib"
}

if target.product.isTest {
if target.product.testsBundle {

let appDependencies = graph.targetDependencies(path: sourceRootPath, name: target.name).filter { targetNode in
targetNode.target.product == .app
}

if let app = appDependencies.first {
settings["TEST_HOST"] = "$(BUILT_PRODUCTS_DIR)/\(app.target.productName)/\(app.target.name)"
settings["BUNDLE_LOADER"] = "$(TEST_HOST)"

settings["TEST_TARGET_NAME"] = "\(app.target.name)"

if target.product == .unitTests {
settings["TEST_HOST"] = "$(BUILT_PRODUCTS_DIR)/\(app.target.productName)/\(app.target.name)"
settings["BUNDLE_LOADER"] = "$(TEST_HOST)"
}

}
}

variantBuildConfiguration.buildSettings = settings
pbxproj.add(object: variantBuildConfiguration)
configurationList.buildConfigurations.append(variantBuildConfiguration)
Expand Down
38 changes: 38 additions & 0 deletions Sources/TuistKit/Generator/ProjectGenerator.swift
Expand Up @@ -103,6 +103,10 @@ final class ProjectGenerator: ProjectGenerating {
sourceRootPath: sourceRootPath,
options: options,
graph: graph)

generateTestTargetIdentity(project: project,
pbxproj: pbxproj,
pbxProject: pbxProject)

return try write(xcodeprojPath: xcodeprojPath,
nativeTargets: nativeTargets,
Expand Down Expand Up @@ -130,6 +134,7 @@ final class ProjectGenerator: ProjectGenerating {
projects: [],
projectRoots: [],
targets: [])

pbxproj.add(object: pbxProject)
pbxproj.rootObject = pbxProject
return pbxProject
Expand Down Expand Up @@ -165,6 +170,39 @@ final class ProjectGenerator: ProjectGenerating {
graph: graph)
return nativeTargets
}

fileprivate func generateTestTargetIdentity(project: Project,
pbxproj: PBXProj,
pbxProject: PBXProject) {

func testTargetName(_ target: PBXTarget) -> String? {

guard let buildConfigurations = target.buildConfigurationList?.buildConfigurations else {
return nil
}

return buildConfigurations
.compactMap { $0.buildSettings["TEST_TARGET_NAME"] as? String }
.first
}

let testTargets = pbxproj.nativeTargets.filter{ $0.productType == .uiTestBundle || $0.productType == .unitTestBundle }

for testTarget in testTargets {

guard let name = testTargetName(testTarget) else {
continue
}

guard let target = pbxproj.targets(named: name).first else {
continue
}

pbxProject.setTargetAttributes([ "TestTargetID": target ], target: testTarget)

}

}

fileprivate func write(xcodeprojPath: AbsolutePath,
nativeTargets: [String: PBXNativeTarget],
Expand Down
4 changes: 0 additions & 4 deletions Sources/TuistKit/Models/Product.swift
Expand Up @@ -189,8 +189,4 @@ extension Product {
var isStatic: Bool {
return [.staticLibrary, .staticFramework].contains(self)
}

var isTest: Bool {
return [.unitTests, .uiTests].contains(self)
}
}
1 change: 1 addition & 0 deletions Tests/TuistKitTests/Generator/ProjectGeneratorTests.swift
Expand Up @@ -48,5 +48,6 @@ final class ProjectGeneratorTests: XCTestCase {
let targetScheme = schemesPath.appending(component: "Target.xcscheme")
XCTAssertTrue(fileHandler.exists(projectScheme))
XCTAssertTrue(fileHandler.exists(targetScheme))

}
}
1 change: 1 addition & 0 deletions features/generate.feature
Expand Up @@ -7,6 +7,7 @@ Feature: Generate a new project using Tuist
Then tuist generates the project
Then I should be able to build the scheme App
Then I should be able to test the scheme AppTests
Then I should be able to test the scheme AppTests
Then I should be able to build the scheme App-Manifest

Scenario: The project is an iOS application with frameworks and tests (ios_app_with_frameworks)
Expand Down
9 changes: 9 additions & 0 deletions fixtures/ios_app_with_tests/Project.swift
Expand Up @@ -25,4 +25,13 @@ let project = Project(name: "App",
],
settings: Settings(base: ["CODE_SIGN_IDENTITY": "",
"CODE_SIGNING_REQUIRED": "NO"])),
Target(name: "AppUITests",
platform: .iOS,
product: .uiTests,
bundleId: "io.tuist.AppUITests",
infoPlist: "Tests.plist",
sources: "UITests/**",
dependencies: [
.target(name: "App"),
])
])
28 changes: 28 additions & 0 deletions fixtures/ios_app_with_tests/UITests/AppUITest.swift
@@ -0,0 +1,28 @@
//Copyright © 2019 Sky. All rights reserved.

import XCTest

class AppUITest: XCTestCase {

override func setUp() {
// Put setup code here. This method is called before the invocation of each test method in the class.

// In UI tests it is usually best to stop immediately when a failure occurs.
continueAfterFailure = false

// UI tests must launch the application that they test. Doing this in setup will make sure it happens for each test method.
XCUIApplication().launch()

// In UI tests it’s important to set the initial state - such as interface orientation - required for your tests before they run. The setUp method is a good place to do this.
}

override func tearDown() {
// Put teardown code here. This method is called after the invocation of each test method in the class.
}

func testExample() {
// Use recording to get started writing UI tests.
// Use XCTAssert and related functions to verify your tests produce the correct results.
}

}

0 comments on commit a57f2e6

Please sign in to comment.