Could not determine bundle identifier for xxxTest TEST_HOST - xcode

We do have troubles getting our CI to work with Xcode. We encounter the issue Could not determine bundle identifier for xxxTest TEST_HOST: some path that does not exist.
What we have done so far:
On the CI Machine we are able to run all tests on the device, but if we trigger it with a commit the CI does end in that error.
We had that issue on other machines too, when we tried to run the tests of the application. We fixed that by cleaning the machine and reboot the devices.(Had do fix some scheme settings) Not we can run all tests but we run into the issue sometimes without any reason.
We also double checked the schemes. The Host Application is set in every Tests scheme to the App itself.
Our project has the following targets:
App
App Unit Tests
App UI Tests
AppeareanceKit (Module)
AppeareanceKit Unit Tests
Models (Module)
Models Unit Test
Found solution:
Diabling the Tests except the App UITest
Run the tests once
Enable all Tests
Run the tests
Question:
What is happening there? How can we prevent from having that issue over and over again?
Known questions:
Xcode 8 Beta - Convert to Current Swift Syntax Failed: Could not find test host
Tests stop working under xcode 8 TEST_HOST error

So after ages of having this issue, we could find the right checkbox to fix this issue.
It somehow sounds weird but the issue was the configurations for the command-line builds inside of the Project settings.
I assume this happens because we always test against the debug configuration and it was set to release. Therefore it did the wrong build for the test host.
This does set the defaultConfigurationName inside of the {projectname}.xcodeproject.
Please comment if you have any more insights of this.

In my app I found a solution.
The problem was of course in the test target.
I hope that this solution will work for you too. Go to your test target build settings.
Search for test host.
In my case this testHost was looking like
build/{buildConfigurationName}-iphoneos/{schemeName}.app/{appName}
Which is wrong as the actual path must be
build/{buildConfigurationName}-iphoneos/{schemeName}.app/{schemeName}
so if you have a build configuration called Alpha, in your app named MyApp, with a scheme called MyApp-Alpha the test host path should be
build/Alpha-iphoneos/MyApp-Alpha.app/MyApp-Alpha
it was
build/Alpha-iphoneos/MyApp-Alpha.app/MyApp
I hope this can help... unfortunately this issue appears in many cases.

One reason to have this error is that your info.plist of your target is not in its path. So if you moved it or removed the reference to it, you may get this error.
So if you moved it, put it back into its place or path. if you removed the reference to it, add it again, close and reopen the project.

Related

MacOS UI Tests Destination on Xcode9 server?

I have reasonable good experiences with Xcode9 server, developing for the Mac. It seems to work, even my unit-test suite is running. However, I struggle with UI tests. My test run out of the IDE, but not in the server, giving me the message:
No destinations were specified with the -destination flag which were
valid for the specified scheme 'UI Tests'.
I tried to add -destination 'platform=OS X,arch=x86_64' to the "arguments passed to xcodebuild" section of the bot, but that seems to be ignored.
I believe that this is somehow related to the fact that UI tests have a defined target. But who knows how to fix it?

Autocomplete not working for test files

Code completion has been a continuing issue for me and lately there's been a new wrinkle. Normally I can just delete the derived data folder and rebuild, sometimes having to exit Xcode, but now I've hit an issue I can't solve.
Auto complete is working in my base project, by that I mean if I'm in a file that is building with the program, code completion works. But if I start writing a test case in a code module that builds with the test target) completion will not work with any of the main target classes or variables.
I have #testable import [target] and it's been working in the past.
The only thing I've done recently is move my repo off my iCloud drive because it was causing Xcode to crash whenever a did a pull onto a local hard drive location.
Is there some location in the project settings that determine where Xcode looks? Is there some hidden cache I need to delete? programming without code completion is a nightmare.
Using the latest 8.2.1 Xcode with all my code in Swift 3.
I have encountered the same problem under Xcode 10.1. The issue seemed to be related to the Build configuration settings of the currently used scheme. Namely, mine were different for the different actions, e.g. Release for the Run action and Debug for the Test action. Changing the build configuration of the Run action to Debug (thus matching the test action one) fixed the issue for me.
Steps I used:
Select your scheme (top left)
Select "Edit scheme"
Make sure the Test and Run actions are using the same build configuration
3.1 If not, select the corresponding action (Test or Run), choose the "Info" tab and change the Configuration from the corresponding picker
I encountered the same problem recently, what I had been trying was:
Cleaning my build folder Alt+Shift+Cmd+K
Building my test target Shift+Cmd+U
I mistakenly believed Xcode 8.2.1 would build my main target, given that it's a #testable import in my unit test classes.
So the steps that worked in the end were:
Cleaning my build folder Alt+Shift+Cmd+K
Building my main target Cmd+B
Building my test target Shift+Cmd+U
After which both the code completion and syntax highlighting return as expected.

Why is MS TestExplorer in VS2015RC not discovering Tests and showing test run result details?

The test explorer (MS-Test) kind of stopped working. It won’t discover any of my tests or sometimes only some of it. When I right click on my test and run it, the output window says “Run test finished: 1 run (time)”, but the test explorer would only display “Last Test Run Failed” (see screenshot), without information about which test or assert failed. I’ve tried restarting the VS, which I thought solved the issue once, but not currently. I’ve also tried build, rebuild, but I just can’t get it working again? Any idea what might help? All of this was working fine until early morning today...
Test Explorer has problems understanding test projects if they are build for x64 or x86, and solution is targeting a different platform.
Also, under Test > Test Settings > Default Test Architecture select appropriate value and then clean and rebuild.

Certain functions/methods not changing when built in Xcode

I am currently working on a project which runs just fine in both the simulator and on device except for one particular method which does not update on the device or in the simulator. It seams that I can put whatever I like in it and it just runs an old version. If I change other methods in the same file they build and run with the changes. Any ideas why this is happening or what I could do to solve it?
One suggestion I heard was to start a new project and copy my code in. I would like to avoid that if possible but it looks like I might have to.
Sometimes you need to do a clean build because Xcode does not always notice dependency changes (e.g. changes to source files).
Some people do not configure their dependencies (e.g. static/dynamic libraries) correctly. If you are using the auto-detect-dependency feature, it still has some bugs, so you may need to configure this explicitly.
FWIW, starting a new project has never been necessary for me...

run tests in mstest without compiling/building

is there a way? do I have to wait for building every time I start the test? I want to build from visual studio not from test
thanks
Any time your code changes and you run your test it is going to do a build... so technically you can run your test over and over again and they will only build the first time, but once you run your test why would you run them again without making a code change?
Couple of things that I use that make your test run faster are:
Check the box for "Only build startup projects and dependencies on Run", located Options->Projects and Solution->Build and Run.
Learn the short cut keys
a. "Ctrl+R, T" Runs test in current context, so if your cursor is inside a test method it will only run that test, but when you do it inside of a non test class it will run all of your test.
b. "Crtl+R, Ctrl+T" Debug test same except debug.
c. Others can be found here, those are 2008 if you need to reference others you can find them via google.
Make sure your test are not calling the database or other time intensive resources, use mocking and stubbing.
Run only small sets of test, ie if I am working in a service class I run only the service class test.
Edit: Reading your question again if you want to build and not from a test you can just go to the menu and click Build->Build Solution or press F6. Also it would be helpful if you indicated which version of visual studio you are using because 2010 is different in the sense that you have to click refresh. Either way are you able to clarify?
This is an old question, but I keep seeing people ask it and the issue is still true in VS2017, and it's also true of other test frameworks (Xunit, etc) run from within VS.
I don't know how to make VS stop building all the time. But I do know how to circumvent the compile - run your tests from a console runner, not from within VS. If you're using ReSharper, it has one.
If you aren't using ReSharper, for MSTest, you can start here. https://msdn.microsoft.com/en-us/library/ms182489.aspx
If you aren't using ReSharper, for XUnit, you can start here. https://xunit.github.io/docs/getting-started-desktop.html#add-xunit-runner-ref
Any changes to source code cause compilation, because in order to run tests VS needs up to date DLL with tests.
If you have already compiled project then you can run test multiple times without compilation.
PS: I run MSTest using TestDriven.NET as for me it is faster.

Resources