Javascript单元测试 [英] Javascript Unit test

查看:79
本文介绍了Javascript单元测试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在250行内有一个javascript应用程序,并希望对此添加测试.每当我进行微小更改时,我都必须手动运行至少10种情况下的测试,这些测试要实现自动化.

I have a javascript app within 250 lines and want to add tests to that. Whenever i make a tiny change, i have to run tests for atleast 10 cases manually, which i want to automate.

我本可以按照不同职位的建议去使用框架,但是我想要的解决方案是最小的摩擦和代码库.像单个文件那样进行单元测试的东西可能会起作用.

I could have gone for frameworks as suggested in different posts, but the solution i want is minimum friction and codebase. Something like a single file for unit testing may work.

有没有一种方法可以在没有任何框架的情况下使用JS测试?我想同时编写单元测试/功能测试.或者,如果框架"是唯一的选择,则从易于插入现有代码+学习曲线的角度来看,首选哪种框架.

Is there a way for using JS testing without any frameworks ? I want to write Unit tests / functional tests both. Or if Frameworks is the only option, what frameworks are preferred in terms os ease of plugin to existing code + learning curve.

推荐答案

在没有任何框架的情况下,使用纯JavaScript很难设置自动化的单元测试.如果您自己尝试重新发明现有的javascript单元测试框架,那可能比编写测试的250行代码要付出巨大的努力.

its really hard to setup automated unit tests with plain javascript without any framework. if you try to reinvent the wheel of existing javascript unit testing framework yourself, that might be huge effort than your 250 lines of code for which you are writing test.

因此,如果您要使用框架,则jasmine和qunitjs是有前途的javascript单元测试框架.

so if you are going for an framework, jasmine and qunitjs are promising unittesting framework for javascript.

http://jasmine.github.io/

https://qunitjs.com/

这篇关于Javascript单元测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆