# Rust-like source-file tests

**URL:** <https://discourse.julialang.org/t/rust-like-source-file-tests/113706>\
**Category:** General Usage\
**Tags:** testing\
**Created:** [May 1, 2024, 8:59pm UTC](https://discourse.julialang.org/t/rust-like-source-file-tests/113706 "2024-05-01T20:59:11Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![algunion](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/algunion/32/51630_2.png) [@algunion](https://discourse.julialang.org/u/algunion)\
**Post date:** [May 1, 2024, 8:59pm UTC](https://discourse.julialang.org/t/rust-like-source-file-tests/113706/1 "2024-05-01T20:59:11Z")

</div>

I find the idiomatic Rust way of writing tests extremely practical, and I can only imagine that such an approach would add even more value to a language like Julia.

Although tools like Copilot can have project-level access, the quality of suggestions seems superior when operating in a source file-level context.

For those not familiar with the Rust test writing, at the end of the/any source file, append the tests relevant to the functionality defined in that file:

```rust
#[cfg(test)]
mod tests {
    # add dependencies and write tests here
}

```

The above will be run when invoking `cargo test`, and (obviously) the tests will not be part of the final/compiled binary.

P. S. I acknowledge the high level of subjectivity and preference when discussing this subject. I am just curious about what the community thinks about this.

---

<div class="post-metadata">

**Author:** ![CameronBieganek](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cameronbieganek/32/6915_2.png) [@CameronBieganek](https://discourse.julialang.org/u/CameronBieganek)\
**Post date:** [May 1, 2024, 9:12pm UTC](https://discourse.julialang.org/t/rust-like-source-file-tests/113706/2 "2024-05-01T21:12:35Z")

</div>

> [@Prerelease of new testing framework and test run UI in VS Code](https://discourse.julialang.org/t/prerelease-of-new-testing-framework-and-test-run-ui-in-vs-code/86355):
>
> I just pushed out a new release of the Julia VS Code extension (1.7.6) to everyone that includes a preview of our new test UI and a general new testing framework for Julia. For a short demo, take a look at our Juliacon talk [https://youtu.be/Okn\_HKihWn8?t=1268](https://youtu.be/Okn_HKihWn8?t=1268). This new set of features consists of two new packages ([TestItems.jl](https://github.com/julia-vscode/TestItems.jl) and [TestItemRunner.jl](https://github.com/julia-vscode/TestItemRunner.jl)) and the new UI in the Julia VS Code extension. A good way to refer to this new test framework is by the “test item” name. How to write test items …

---

<div class="post-metadata">

**Author:** ![algunion](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/algunion/32/51630_2.png) [@algunion](https://discourse.julialang.org/u/algunion)\
**Post date:** [May 1, 2024, 9:20pm UTC](https://discourse.julialang.org/t/rust-like-source-file-tests/113706/3 "2024-05-01T21:20:12Z")

</div>

Now, I am wondering what other gems I am missing.

Somebody _should_ write an article: _Fantastic Packages and where to find them!_

---

<div class="post-metadata">

**Author:** ![gdalle](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gdalle/32/224680_2.png) [@gdalle](https://discourse.julialang.org/u/gdalle)\
**Post date:** [May 2, 2024, 5:59am UTC](https://discourse.julialang.org/t/rust-like-source-file-tests/113706/4 "2024-05-02T05:59:57Z")

</div>

> [@algunion](#):
>
> Somebody _should_ write an article: _Fantastic Packages and where to find them!_

I think you misspelled

[https://modernjuliaworkflows.github.io/sharing/#testing](https://modernjuliaworkflows.github.io/sharing/#testing)

---

<div class="post-metadata">

**Author:** ![algunion](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/algunion/32/51630_2.png) [@algunion](https://discourse.julialang.org/u/algunion)\
**Post date:** [May 2, 2024, 7:16am UTC](https://discourse.julialang.org/t/rust-like-source-file-tests/113706/5 "2024-05-02T07:16:45Z")

</div>

[MoJuWo](https://modernjuliaworkflows.github.io/) was my first stop before posting the question.

I am unsure if putting _testing_ under the _sharing_ category aids discoverability (maybe it will not matter so much once a search functionality is added to MoJuWo).

---

<div class="post-metadata">

**Author:** ![jbytecode](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jbytecode/32/17719_2.png) [@jbytecode](https://discourse.julialang.org/u/jbytecode)\
**Post date:** [May 2, 2024, 7:21am UTC](https://discourse.julialang.org/t/rust-like-source-file-tests/113706/6 "2024-05-02T07:21:48Z")

</div>

Wouldn’t including unused test code in the source code increase the compilation time each time the code is included in the Julia? I think this test section should be omitted in the parsing level of compilation which seems like a comprehensive change - which in turn with a computation overhead in each single use of `include` ?

---

<div class="post-metadata">

**Author:** ![ffevotte](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ffevotte/32/6587_2.png) [@ffevotte](https://discourse.julialang.org/u/ffevotte)\
**Post date:** [May 2, 2024, 7:46am UTC](https://discourse.julialang.org/t/rust-like-source-file-tests/113706/7 "2024-05-02T07:46:49Z")

</div>

> [@jbytecode](#):
>
> I think this test section should be omitted in the parsing level of compilation which seems like a comprehensive change - which in turn with a computation overhead in each single use of `include` ?

Yes, this is more or less what’s done in `TestItems.jl`: `@testitem` code blocks are expanded to literally `nothing` at macro expansion time, so that they are not compiled.

Sure, this probably incurs some overhead when `include`ing test files, but I doubt it is significant.

---

<div class="post-metadata">

**Author:** ![gdalle](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gdalle/32/224680_2.png) [@gdalle](https://discourse.julialang.org/u/gdalle)\
**Post date:** [May 2, 2024, 7:47am UTC](https://discourse.julialang.org/t/rust-like-source-file-tests/113706/8 "2024-05-02T07:47:52Z")

</div>

Sorry for the aside

> [@algunion](#):
>
> I am unsure if putting _testing_ under the _sharing_ category aids discoverability

Maybe it’s the name of the category that’s not optimal? How about “Packaging”?

> [@algunion](#):
>
> maybe it will not matter so much once a search functionality is added to MoJuWo

I don’t know if there is a way to do that with the standard Franklin themes? @tlienart would know

[https://tlienart.github.io/FranklinTemplates.jl/](https://tlienart.github.io/FranklinTemplates.jl/)
