# UnitTest project directory structure for libraries and submodules?

**URL:** <https://chapel.discourse.group/t/unittest-project-directory-structure-for-libraries-and-submodules/46243>\
**Category:** Users\
**Created:** [November 19, 2025, 1:12pm UTC](https://chapel.discourse.group/t/unittest-project-directory-structure-for-libraries-and-submodules/46243 "2025-11-19T13:12:28Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![jmag722](https://avatars.discourse-cdn.com/v4/letter/j/bbce88/32.png) [@jmag722](https://chapel.discourse.group/u/jmag722)\
**Post date:** [November 19, 2025, 1:12pm UTC](https://chapel.discourse.group/t/unittest-project-directory-structure-for-libraries-and-submodules/46243/1 "2025-11-19T13:12:29Z")

</div>

Hello, I had a question about project file structure for a Chapel library. I’m confident I have the src directory structure working, per the great discussion in [Importing files from subfolders](https://chapel.discourse.group/t/importing-files-from-subfolders/17064) . I’m assuming:

```Chapel
src/
  MyLibrary.chpl
  MyLibrary/
    Submodule1.chpl
    Submodule2.chpl

```

Now I’d like to write UnitTests for that hierarchical library structure. I was thinking something like

```bash
test/
  MyLibraryTest.chpl
  MyLibraryTest/
    Submodule1Test.chpl
    Submodule2Test.chpl

```

Where `MyLibraryTest` simply includes the lower test submodules and calls UnitTest.main(). In `Submodule1Test` I then have

```chapel
module Submodule1Test {
  use UnitTest;
  import Submodule1;
  // tests go here
}

```

But Mason is unable to find Submodule1, and won’t be able to run the tests. Should I move to a flat test directory structure?

```Chapel
test/
  Submodule1Test.chpl
  Submodule2Test.chpl

```

I think this would work, but then each test file would need a

```chapel
proc main() throws {UnitTest.main();}

```

is that best practice?

---

<div class="post-metadata">

**Author:** ![e-kayrakli](https://yyz2.discourse-cdn.com/free1/user_avatar/chapel.discourse.group/e-kayrakli/32/134_2.png) [@e-kayrakli](https://chapel.discourse.group/u/e-kayrakli)\
**Post date:** [November 19, 2025, 1:52pm UTC](https://chapel.discourse.group/t/unittest-project-directory-structure-for-libraries-and-submodules/46243/2 "2025-11-19T13:52:05Z")

</div>

Hello @jmag722,

As a quick response, I wouldn't be surprised at all if `UnitTest` or `mason test` has some gaps w.r.t. walking a directory tree the same way our compiler does.

> is that best practice?

Today, that's the case. In my Mason packages, I have flat structure and that line in all of the files. That's not to say that we should be satisfied with that, though. 🙂

Engin

---

<div class="post-metadata">

**Author:** ![jmag722](https://avatars.discourse-cdn.com/v4/letter/j/bbce88/32.png) [@jmag722](https://chapel.discourse.group/u/jmag722)\
**Post date:** [November 19, 2025, 2:04pm UTC](https://chapel.discourse.group/t/unittest-project-directory-structure-for-libraries-and-submodules/46243/3 "2025-11-19T14:04:32Z")

</div>

Thank you Engin. I also noticed with the VSCode extension, where you can run the tests directly in the editor, I believe it needs `UnitTest.main` in each file or it can’t run the tests (it could “Run All” from my `MyLibraryTest.chpl` but not individual tests from the submodule tests).

---

<div class="post-metadata">

**Author:** ![e-kayrakli](https://yyz2.discourse-cdn.com/free1/user_avatar/chapel.discourse.group/e-kayrakli/32/134_2.png) [@e-kayrakli](https://chapel.discourse.group/u/e-kayrakli)\
**Post date:** [November 19, 2025, 2:09pm UTC](https://chapel.discourse.group/t/unittest-project-directory-structure-for-libraries-and-submodules/46243/4 "2025-11-19T14:09:00Z")

</div>

Hmm, that could be the extension inheriting the behavior from UnitTest. But I'll tag @jabraham to make sure that they see it and in case there is an issue with the extension.

Engin

---

<div class="post-metadata">

**Author:** ![jabraham](https://yyz2.discourse-cdn.com/free1/user_avatar/chapel.discourse.group/jabraham/32/430_2.png) [@jabraham](https://chapel.discourse.group/u/jabraham)\
**Post date:** [November 19, 2025, 4:59pm UTC](https://chapel.discourse.group/t/unittest-project-directory-structure-for-libraries-and-submodules/46243/5 "2025-11-19T16:59:00Z")

</div>

> [@jmag722](#):
>
> I also noticed with the VSCode extension, where you can run the tests directly in the editor, I believe it needs `UnitTest.main` in each file or it can’t run the tests (it could “Run All” from my `MyLibraryTest.chpl` but not individual tests from the submodule tests).

That's correct, each file needs its own UnitTest.main. If you have a single UnitTest.main and include multiple files with tests of their own, `mason` should understand that fine, but the VSCode extension won't. But this is definitely on the roadmap as future work

-Jade

---

<div class="post-metadata">

**Author:** ![jmag722](https://avatars.discourse-cdn.com/v4/letter/j/bbce88/32.png) [@jmag722](https://chapel.discourse.group/u/jmag722)\
**Post date:** [November 20, 2025, 4:20am UTC](https://chapel.discourse.group/t/unittest-project-directory-structure-for-libraries-and-submodules/46243/6 "2025-11-20T04:20:47Z")

</div>

Thanks you both, flattening the test structure allows VS code tests to run individually. Structured now like:

```chapel
module MyLibrary {
  include module Submodule1;
  include module Submodule2;

  public import this.Submodule1;
  public import this.Submodule2;
}

```

with

```chapel
module Submodule1Test {
  use UnitTest;

  import MyLibrary.Submodule1;
  // ...
}

```

allowed tests to run in both the editor and with `mason test`. But the `import MyLibrary.Submodule1Test` still had a red squiggly saying `MyLibrary` couldn’t be found, but guess it’s not a problem.

-Jared

---

<div class="post-metadata">

**Author:** ![jabraham](https://yyz2.discourse-cdn.com/free1/user_avatar/chapel.discourse.group/jabraham/32/430_2.png) [@jabraham](https://chapel.discourse.group/u/jabraham)\
**Post date:** [November 20, 2025, 5:55pm UTC](https://chapel.discourse.group/t/unittest-project-directory-structure-for-libraries-and-submodules/46243/7 "2025-11-20T17:55:10Z")

</div>

Thats due to `chpl-language-server` in VSCode not being able to understand your project structure, whereas mason understands it out of the box. Its not a problem, its just a visual thing. But you can resolve it.

There's an open issue about better out of the box support for mason projects, [[Feature Request]: Integrate CLS better with Mason · Issue #25120 · chapel-lang/chapel · GitHub](https://github.com/chapel-lang/chapel/issues/25120). But you can also add the following to the bottom of your mason file and the red error lines will go away

```Chapel
[tool.chpl-language-server]
module-dir = ["src"]

```

-Jade

---

<div class="post-metadata">

**Author:** ![jmag722](https://avatars.discourse-cdn.com/v4/letter/j/bbce88/32.png) [@jmag722](https://chapel.discourse.group/u/jmag722)\
**Post date:** [November 21, 2025, 2:57am UTC](https://chapel.discourse.group/t/unittest-project-directory-structure-for-libraries-and-submodules/46243/8 "2025-11-21T02:57:32Z")

</div>

Thank you Jade, that did the trick!

Best,

Jared
