简体   繁体   English

何时使用带有笑话和酵素的单元测试或快照测试?

[英]When to use unit testing or snapshot testing with jest and enzyme?

我开始用玩笑和酶为我的react应用程序编写测试,以测试本机和前端,并且我想清楚何时使用快照测试以及何时使用单元测试。

Snapshots are a tool used in unit testing. 快照是用于单元测试的工具。 If you don't use snapshots, then you end up with large chunks of test data in your unit test code. 如果不使用快照,那么最终在单元测试代码中会得到大量测试数据。 For example, imagine you are testing a function that returns a hundred lines of text, like a blog post. 例如,假设您正在测试一个返回一百行文本的函数,例如博客文章。 One way would be to have an expect(blogPost).toBe(thisHugeStringOfManyLines) . 一种方法是使用expect(blogPost).toBe(thisHugeStringOfManyLines) We can use snapshots to easily manage large chunks of test data. 我们可以使用快照轻松管理大量测试数据。 Jest creates separate files for test data, and provides an easy diffing mechanism to see what parts of data has changed. Jest为测试数据创建了单独的文件,并提供了一种简单的区分机制,以查看数据的哪些部分已更改。 In case of react and enzyme, the testing data is JSX. 如果有反应和酶,则测试数据为JSX。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM