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

Issue with @testable import test #4

Closed
remirobert opened this issue Dec 22, 2017 · 11 comments
Closed

Issue with @testable import test #4

remirobert opened this issue Dec 22, 2017 · 11 comments

Comments

@remirobert
Copy link

remirobert commented Dec 22, 2017

I am currently having an issue, in my tests, I am using @testable import to access the API code I want to test.

Here my BUCK:

buck test :chatApp

apple_asset_catalog(
  name = 'Assets',
  app_icon = 'AppIcon',
  dirs = ['app/Assets.xcassets'],
)

apple_resource(
  name = 'appResources',
  files = glob(['app/*.png', 'app/**/*.storyboard']),
)

apple_bundle(
  name = 'app',
  binary = ':appBinary',
  extension = 'app',
  info_plist = 'app/Info.plist',
  tests = [':appTests']
)

apple_binary(
  name = 'appBinary',
  deps = [':appResources', ':Assets'],
  srcs = glob([
    'app/**/*.swift'
  ]),
  frameworks = [
    '$SDKROOT/System/Library/Frameworks/UIKit.framework',
    '$SDKROOT/System/Library/Frameworks/Foundation.framework',
  ]
)

apple_package(
  name = 'appPackage',
  bundle = ':app'
)

apple_test(
  name = 'appTests',
  test_host_app = ':app',
  run_test_separately = True,
  info_plist = 'appTests/Info.plist',
  srcs = glob([
    'appTests/**/*.swift'
  ]),
  frameworks = [
    '$SDKROOT/System/Library/Frameworks/Foundation.framework',
    '$SDKROOT/System/Library/Frameworks/UIKit.framework',
    '$PLATFORM_DIR/Developer/Library/Frameworks/XCTest.framework',
  ]
)

I am having a runtime crash.
Is it possible to have the @testable import?
If not what is the other alternative to test my code?

Here the error :

Building... 0.4 sec
[2017-12-18 16:21:26.111][error][command:null][tid:465][com.facebook.buck.cli.Main] Uncaught exception at top level
java.lang.NullPointerException
	at java.util.Objects.requireNonNull(Objects.java:203)
	at java.util.Optional.<init>(Optional.java:96)
	at java.util.Optional.of(Optional.java:108)
	at com.facebook.buck.apple.AppleTestDescription.createTestHostInfo(AppleTestDescription.java:496)
	at com.facebook.buck.apple.AppleTestDescription.createBuildRule(AppleTestDescription.java:233)
	at com.facebook.buck.apple.AppleTestDescription.createBuildRule(AppleTestDescription.java:84)
	at com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer.transform(DefaultTargetNodeToBuildRuleTransformer.java:88)
	at com.facebook.buck.rules.SingleThreadedBuildRuleResolver.lambda$requireRule$0(SingleThreadedBuildRuleResolver.java:111)
	at com.facebook.buck.rules.SingleThreadedBuildRuleResolver.computeIfAbsent(SingleThreadedBuildRuleResolver.java:84)
	at com.facebook.buck.rules.SingleThreadedBuildRuleResolver.requireRule(SingleThreadedBuildRuleResolver.java:107)
	at com.facebook.buck.swift.SwiftLibraryDescription.createCompanionBuildRule(SwiftLibraryDescription.java:391)
	at com.facebook.buck.apple.AppleLibraryDescription.lambda$requireSingleArchUnstrippedBuildRule$8(AppleLibraryDescription.java:587)
	at java.util.Optional.flatMap(Optional.java:241)
	at com.facebook.buck.apple.AppleLibraryDescription.requireSingleArchUnstrippedBuildRule(AppleLibraryDescription.java:585)
	at com.facebook.buck.apple.AppleLibraryDescription.requireUnstrippedBuildRule(AppleLibraryDescription.java:546)
	at com.facebook.buck.apple.AppleLibraryDescription.createLibraryBuildRule(AppleLibraryDescription.java:441)
	at com.facebook.buck.apple.AppleTestDescription.createTestLibraryRule(AppleTestDescription.java:411)
	at com.facebook.buck.apple.AppleTestDescription.createBuildRule(AppleTestDescription.java:251)
	at com.facebook.buck.apple.AppleTestDescription.createBuildRule(AppleTestDescription.java:84)
	at com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer.transform(DefaultTargetNodeToBuildRuleTransformer.java:88)
	at com.facebook.buck.rules.SingleThreadedBuildRuleResolver.lambda$requireRule$0(SingleThreadedBuildRuleResolver.java:111)
	at com.facebook.buck.rules.SingleThreadedBuildRuleResolver.computeIfAbsent(SingleThreadedBuildRuleResolver.java:84)
	at com.facebook.buck.rules.SingleThreadedBuildRuleResolver.requireRule(SingleThreadedBuildRuleResolver.java:107)
	at com.facebook.buck.rules.ActionGraphCache$2.visit(ActionGraphCache.java:330)
	at com.facebook.buck.rules.ActionGraphCache$2.visit(ActionGraphCache.java:327)
	at com.facebook.buck.graph.AbstractBottomUpTraversal.traverse(AbstractBottomUpTraversal.java:36)
	at com.facebook.buck.rules.ActionGraphCache.createActionGraphSerially(ActionGraphCache.java:332)
	at com.facebook.buck.rules.ActionGraphCache.createActionGraph(ActionGraphCache.java:264)
	at com.facebook.buck.rules.ActionGraphCache.getActionGraph(ActionGraphCache.java:167)
	at com.facebook.buck.rules.ActionGraphCache.getActionGraph(ActionGraphCache.java:68)
	at com.facebook.buck.cli.TestCommand.runWithoutHelp(TestCommand.java:549)
	at com.facebook.buck.cli.AbstractCommand.run(AbstractCommand.java:232)
	at com.facebook.buck.cli.AbstractContainerCommand.run(AbstractContainerCommand.java:79)
	at com.facebook.buck.cli.BuckCommand.run(BuckCommand.java:82)
	at com.facebook.buck.cli.Main.runMainWithExitCode(Main.java:1101)
	at com.facebook.buck.cli.Main.runMainThenExit(Main.java:395)
	at com.facebook.buck.cli.Main.nailMain(Main.java:1855)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at com.martiansoftware.nailgun.NGSession.run(NGSession.java:329)
@zayhero-zz
Copy link
Collaborator

@remirobert are you using the sample repo or your own repo? I didn't see anything related to @testable here.

@remirobert
Copy link
Author

My own.
On this repo, there is no test target.
So if you want to test your app, how will you do?

@zayhero-zz
Copy link
Collaborator

Buck itself provide the guideline about how to config apple_test build rule: https://buckbuild.com/rule/apple_test.html
We are able to use @testable in our codebase, which is doing almost the same thing as what we do in apple_library.

In our migration, we did encounter some cases that @testable fail, but that's mostly due to there is swift module in the module which being tested.
But without looking into your code / config, I can't tell what's exactly broken.

@remirobert
Copy link
Author

I have read the documentation, and tried different settings, but at this end I always got that runtime crash.
I created a sample project with the configuration I am using, and reproducing the crash with a test target : https://github.com/remirobert/test-fail-testable-import

Thanks for your help.

@zayhero-zz
Copy link
Collaborator

you need to add deps = [':app'] into the apple_test build rule so that you can use the app module.
Also, your crash is due to use are setting test_host_app = ':app', I think that's probably not the correct way, I remove this line and the test is able to build

@remirobert
Copy link
Author

Yes without the test_host_app = ':app' it's building fine.
But I can't use the @testable import app in my tests.
My understanding is that test_host_app allows you to do that.

@remirobert
Copy link
Author

I found an Objc example working with the test_host_app : https://github.com/bhamiltoncx/buck-ios-sample

@zayhero-zz
Copy link
Collaborator

Nope, it’s not related. You need to put “deps” into the test build rule to make it build.

@zayhero-zz
Copy link
Collaborator

Closing this since the problem should have been resolved

@pomozoff
Copy link

pomozoff commented Sep 7, 2020

@zayhero, Still doesn't build even adding deps = [':app'], into BUCK:

apple_test(
  name = 'appTests',
  deps = [':app'],
  test_host_app = ':app',
  run_test_separately = True,
  info_plist = 'appTests/Info.plist',
  srcs = glob([
    'appTests/**/*.swift'
  ]),
  frameworks = [
    '$SDKROOT/System/Library/Frameworks/Foundation.framework',
    '$SDKROOT/System/Library/Frameworks/UIKit.framework',
    '$PLATFORM_DIR/Developer/Library/Frameworks/XCTest.framework',
  ]
)

@pomozoff
Copy link

pomozoff commented Sep 7, 2020

@remirobert, it builds because there are no swift sources in srcs section added.
I'm debugging buck and see it tries to build a SwiftLibrary that has no output path and this is the root cause of the NPE.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants