# .env files are not found when running unit tests using Xcode 26.4

**URL:** <https://forums.swift.org/t/env-files-are-not-found-when-running-unit-tests-using-xcode-26-4/86043>\
**Category:** Vapor\
**Tags:** vapor, testing\
**Created:** [April 15, 2026, 1:41pm UTC](https://forums.swift.org/t/env-files-are-not-found-when-running-unit-tests-using-xcode-26-4/86043 "2026-04-15T13:41:19Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![marco.masser](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/marco.masser/32/6010_2.png) [@marco.masser](https://forums.swift.org/u/marco.masser)\
**Post date:** [April 15, 2026, 1:41pm UTC](https://forums.swift.org/t/env-files-are-not-found-when-running-unit-tests-using-xcode-26-4/86043/1 "2026-04-15T13:41:19Z")

</div>

This isn’t directly related to Vapor and certainly not Vapor’s fault, but I’ve run into this issue in a Vapor project and I assume other people who follow [Vapor’s documentation](https://docs.vapor.codes/getting-started/xcode/) are affected by this, too:

According to the [release notes of Xcode 26.4](https://developer.apple.com/documentation/xcode-release-notes/xcode-26_4-release-notes), an issue was resolved:

> - Fixed: When running unit test targets with no host application, the test runner is now consistently launched with a default working directory of `/tmp`, from both Xcode and xcodebuild. (162549425)

This Vapor project I’m working on has relied on the app itself as well as the unit tests loading the `.env` files from the current working directory, as implemented by `static DotEnvFile.load(for:fileio:logger:)` in Vapor. The project is a Swift package that we open in Xcode and as [described in the Vapor documentation](https://docs.vapor.codes/getting-started/xcode/), everyone working on this project sets the working directory in Xcode’s scheme editor (the one Xcode implicitly generates at `.swiftpm/xcode/package.xcworkspace/`) to the project root because that’s where the `.env` files are located:

 ![Scheme editor in Xcode showing custom working directory configuration.](https://global.discourse-cdn.com/swift/original/3X/c/0/c0dabf54247753c8dac790b38b94330eff83edc1.jpeg)

This works just fine when running the app, but starting with Xcode 26.4, it doesn’t work anymore when running the unit tests. Previously, it seemed like the _Run_ action’s working directory was implicitly used for the _Test_ action, but that doesn’t happen anymore (see quoted release notes above). Unfortunately, the UI for the _Test_ action looks differently and there is no way to set a custom working directory for the unit tests:

 ![Different scheme editor for test action.](https://global.discourse-cdn.com/swift/original/3X/e/7/e7039e6158789150daa57ae63893b96ebdda9610.jpeg)

The result is that Vapor fails to load the `.env` files when running unit tests because they are not located in `/tmp`, obviously.

So my question is: How do other people deal with this? Is there a better way to set all this up?

Since this approach is the only one mentioned in the Vapor documentation, I assume others are also doing it this way. One workaround we found is using `FileManager.default.changeCurrentDirectoryPath(_:)` before calling Vapor’s `static Application.make(_:_:)`, but that doesn’t seem right and it’s also not clear how to best pass in the path to set. I also tried setting the `PWD` environment variable using the scheme editor, but that does not seem to work.

Not really relevant, but this is using Vapor version 4.121.4.

---

<div class="post-metadata">

**Author:** ![oden3d](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/oden3d/32/45126_2.png) [@oden3d](https://forums.swift.org/u/oden3d)\
**Post date:** [April 17, 2026, 10:06am UTC](https://forums.swift.org/t/env-files-are-not-found-when-running-unit-tests-using-xcode-26-4/86043/2 "2026-04-17T10:06:25Z")

</div>

Same here — testing isn’t working in Xcode 26.4 or 26.4.1.  
Using Xcode 26.3 allows all tests to run successfully.

I also tried moving the `.env` file to the project root, but that didn’t help.

Any workarounds?

---

<div class="post-metadata">

**Author:** ![marco.masser](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/marco.masser/32/6010_2.png) [@marco.masser](https://forums.swift.org/u/marco.masser)\
**Post date:** [April 17, 2026, 10:20am UTC](https://forums.swift.org/t/env-files-are-not-found-when-running-unit-tests-using-xcode-26-4/86043/3 "2026-04-17T10:20:04Z")

</div>

The workaround I mentioned at the end (using `FileManager.default.changeCurrentDirectoryPath(_:)` before calling Vapor’s `static Application.make(_:_:)`) works, but it’s cumbersome because you either have to hardcode the path or pass it in via some other way (e.g. an environment variable configured in the Xcode scheme).

---

<div class="post-metadata">

**Author:** ![marco.masser](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/marco.masser/32/6010_2.png) [@marco.masser](https://forums.swift.org/u/marco.masser)\
**Post date:** [April 17, 2026, 10:29am UTC](https://forums.swift.org/t/env-files-are-not-found-when-running-unit-tests-using-xcode-26-4/86043/4 "2026-04-17T10:29:02Z")

</div>

FYI, I also opened a GitHub issue about this: [Behavior change in Xcode 26.4 causes Vapor to not find .env files in unit test, rendering documentation invalid · Issue #3454 · vapor/vapor · GitHub](https://github.com/vapor/vapor/issues/3454)

---

<div class="post-metadata">

**Author:** ![marco.masser](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/marco.masser/32/6010_2.png) [@marco.masser](https://forums.swift.org/u/marco.masser)\
**Post date:** [April 17, 2026, 11:41am UTC](https://forums.swift.org/t/env-files-are-not-found-when-running-unit-tests-using-xcode-26-4/86043/5 "2026-04-17T11:41:45Z")

</div>

…and now I also filed a feedback: FB22530511 (should be a duplicate of FB22357181).
