简体   繁体   English

如何在 main.rs 之外进行单元测试?

[英]How to unit test outside of main.rs?

I'm new to Rust, I have a file structure like this我是 Rust 的新手,我有这样的文件结构

  • main.rs主要.rs

  • chip8.rs芯片8.rs

  • chip8_gui.rs chip8_gui.rs

I added a unit test in main.rs and a unit test in chip8.rs (a simple assert_eq,(2,2) ) but it only finds the test in main.rs.我在 main.rs 中添加了一个单元测试,在 chip8.rs 中添加了一个单元测试(一个简单的assert_eq,(2,2) ),但它只在 main.rs 中找到测试。 Why?为什么? I am trying to test a private function of chip8.rs.我正在尝试测试 chip8.rs 的私有 function。

Turns out TDD is fun, but you have to make sure it compiles!事实证明 TDD 很有趣,但你必须确保它可以编译! The solution was simply to add mod chip8 in main.rs解决方案只是在main.rs中添加mod chip8

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在 src/main.rs 中定义的类型在 tests/test.rs 文件中无法识别 - Types defined in src/main.rs are not recognized in tests/test.rs file 如何在 VisualStudio 中对 main() 进行单元测试 - How to unit test main() in VisualStudio 如何对主要职责是重定向到应用程序外部页面的Angular Service进行单元测试? - How to unit test an Angular Service whose main responsibility is to redirect to a page outside of the application? 单元测试项目如何测试main() - How does unit test project test main() 如何在主 class 之外测试一个 function? - How to test a function outside the main class? 如何在视觉工作室之外对项目进行单元测试 - How to unit test a project outside visual studio 如何使用 Pytest 为 Python 中的主要 function 编写单元测试 - How to write a unit test using Pytest for the main function in Python 如何在电子应用程序的主要过程中对组件进行单元测试? - how to unit test components in main process of an electron app? 你如何在 Java 中对 main 方法进行单元测试? - How do you unit test main method in Java? 如何使用 main 函数在现有项目上运行单元测试 - How to run a unit test on an existing project with main function
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM