有多少集成测试,每个 Jest 测试文件有多少?

How many integration tests, and how many per Jest testing file?

我目前正在 运行 使用 NestJS 开玩笑,我正在编写一些集成测试。

我在 Jest 中遇到了一些计时问题,想知道这是否与我的文件中的测试数量有关。我最大的文件中有 9 个 describe 块,以及 32 个 testit 块 - 这也是许多?

作为一个更笼统的问题,我应该编写多少个集成测试?所有这些测试都与我的应用程序的 login/register 功能有关 - 这太多了吗?我可以进行 太多 测试吗?

请有人指出 how/where 我可以找到关于 Jest 和集成测试的约定吗?

I have 9 describe blocks, and 32 test and it blocks in my largest file - is this too many?

我不知道 Jest,但我会选择“不”。 9个块和32个测试非常小。

As a more general question, how many integration tests should I write?

涵盖您的功能、边缘情况和 prevent bugs from reoccurring

All of these tests are to do with the login/register functionality of my app - is this too many?

取决于您的 login/registration 流程的复杂程度,以及它可能出错的不同方式。但是,请记住,其中大部分应该作为单元测试来完成。例如,当注册电子邮件发送失败时发生的情况的测试将是一个单元测试。而确认用户在注册后被重定向将是一个集成测试。

Can I ever have too many tests?

没有。但是你的测试可能写得不好。

这些答案可能看起来油嘴滑舌,但正如 Lines Of Code (LOC) 是一个糟糕的指标一样,测试次数也是一个糟糕的指标。这是一个不灵活的数字,没有考虑到您正在测试的内容。

因为他们负责测试代码,所以您的测试反映了代码的复杂性,并且通常与您的代码库一样大或更大。

Please could someone also point out how/where can I find out about conventions for Jest and integration testing as a whole?

虽然这不是 Jest 特有的,"A Node.js Guide to Actually Doing Integration Tests" provides a good overview. The Jest documentation has an example of testing a React app and lists tutorials for other frameworks