4

Here on my current configuration (Big Sur 11.1 (20C69), Xcode 12.3 (12C33)) I have an problem

withCouldNotFindInputNodeInBuiltGraphError<XcodeGraphSource, PreviewTranslationUnit>: WeeklyPlanViewModel_Tests.swift not found in any targets
WeeklyPlanViewModel_Tests.swift must belong to at least one target in the current scheme in order to use previews

and no of my changes bring me to get preview running again.

Clearing the project-build, deleting complete "DerivedData", also deactivating of this unittest-file (it is only this one available) and complete removing of unittest-target from the project: nothing helped to fix the preview-functionality.

What can I do in addition to get preview run again?

Interesting fact is, when creating an project new, copy all the files (without any tests) inside the project, and try out the preview, it works some time. But I cannot develop without testing. After git-commit and inserting some testing files, it works one-two times, then it stops. And no git-reverting to the previous commit, brings preview again to life.

fanton
  • 71
  • 4
  • I also have this problem on my machine. It's frustrating because there's no clear underlying cause. It also seems to be pretty rare. I've been able to get back previews by the routine of quit/delete derived data/start Xcode/remove unittests/run preview/add unittest. And exactly like you, I've been rebuilding the complete project. That's how I'm pushing off the problem. I'm hoping this issue gets fixed, that's all we seem to be able to do right now. – Bart van Kuik Feb 04 '21 at 09:32
  • I started experiencing this problem today. I've been working on unit tests for the past few days, so I'm not sure if that has something to do with it. @BartvanKuik your fix doesn't work for me. – LondonGuy Jun 22 '21 at 09:11
  • @LondonGuy yeah it stopped working for me, too. What helped, is throwing all unittests in one giant file. It's an atrocity but it helps. – Bart van Kuik Jun 22 '21 at 09:28
  • @BartvanKuik I managed to fix it. I've posted an answer. – LondonGuy Jun 22 '21 at 23:02

2 Answers2

2

I managed to fix the issue. I think Xcode got confused somewhere down the line when I started creating separate groups inside my main Tests group to hold various test files.

How I fixed it:

  1. Rename the class. So for example, my test class was originally SomeClass. I renamed it to SomeClass2.

  2. Create a new test file using File > New > File and give it the original name of the class you renamed SomeClass

  3. Copy and paste your tests into that file.

  4. Delete the old test file.

This instantly fixed the issue for me. I guess something went wrong in Xcode and it couldn't locate the problematic file.

LondonGuy
  • 10,778
  • 11
  • 79
  • 151
0

I used to have this problem all the time, but realized I haven't had it in a while. I think it's because I'm using Xcode 13b1 most of the time (b2 and b3 break our source code for now).

I think I solved this issue by removing and re-adding the file. It wasn't enough to remove it from the target, I had to remove it from the project, then drop it back in.

Rick
  • 3,298
  • 3
  • 29
  • 47