When I try to make a unit test target for my macOS app that uses Objective-C, running tests fails, and the debugging log shows a message "Creating more than one Application". If, on the other hand, when I create the unit test target, I select "None" as the target to be tested, and then add all my sources to that target, my tests work. So, I can get my testing done, but I think I must be doing something wrong.
By the way, along with the error message, there is a stack crawl:
0 CoreFoundation 0x00007ff8140410aa __exceptionPreprocess + 242
1 libobjc.A.dylib 0x00007ff813b660b7 objc_exception_throw + 48
2 Foundation 0x00007ff814f19bd8 -[NSCalendarDate initWithCoder:] + 0
3 AppKit 0x00007ff817030062 -[NSApplication init] + 1718
4 XCTestCore 0x000000010774b0df -[XCTestDriver _createTestBundlePrincipalClassInstance] + 82
5 XCTestCore 0x0000000107749338 -[XCTestDriver _runTests] + 111
6 XCTestCore 0x000000010770f194 _XCTestMain + 126
7 libXCTestBundleInject.dylib 0x0000000106e8982d __copy_helper_block_e8_32s + 0
8 CoreFoundation 0x00007ff813fc9a91 __CFRUNLOOP_IS_CALLING_OUT_TO_A_BLOCK__ + 12
9 CoreFoundation 0x00007ff813fc99ca __CFRunLoopDoBlocks + 398
10 CoreFoundation 0x00007ff813fc883d __CFRunLoopRun + 898
11 CoreFoundation 0x00007ff813fc7e51 CFRunLoopRunSpecific + 560
12 HIToolbox 0x00007ff81da52f3d RunCurrentEventLoopInMode + 292
13 HIToolbox 0x00007ff81da52b84 ReceiveNextEventCommon + 199
14 HIToolbox 0x00007ff81da52aa8 _BlockUntilNextEventMatchingListInModeWithFilter + 64
15 AppKit 0x00007ff8170689d8 _DPSNextEvent + 858
16 AppKit 0x00007ff817067882 -[NSApplication(NSEvent) _nextEventMatchingEventMask:untilDate:inMode:dequeue:] + 1214
17 AppKit 0x00007ff817059ef7 -[NSApplication run] + 586
18 AppKit 0x00007ff81702e111 NSApplicationMain + 817
19 PlainCalc 0x00000001057d0a91 main + 65
20 dyld 0x00007ff813b93418 start + 1896
OK, I seem to have solved it. I had a .xcconfig file at the project level that specified
INFOPLIST_KEY_NSPrincipalClass = NSApplication
Apparently the test target is not supposed to specify a principal class.
So, thanks for suggesting that I try a newly created project, which I should have thought of.