What are some JavaScript Unit Testing and Mocking

2019-01-29 22:10发布

My main JavaScript framework is jQuery so I would like my unit test and mocking frameworks to be compatible with that. I'd rather not have to introduce another JavaScript framework.

I am currently using QUnit for unit testing and Jack for mocking, but I am pretty new to the whole unit testing of JavaScript.

Does anyone else have a better tool to suggest? What has worked for you?

14条回答
欢心
2楼-- · 2019-01-29 22:22

I'm not sure why no one has mentioned JsTestDriver! It has to be the one of the only JS Testing tools that actually work like you'd expect them to if you've used unit testing tools in other languages.

Running tests can be done without touching a browser, you can integrate it with IDE's, you can integrate it with Continuous integration systems... Oh, and it's fast, and can run tests in multiple browsers at the same time.

You can also use other testing frameworks like YUITest with it, making it even better.

查看更多
【Aperson】
3楼-- · 2019-01-29 22:24

YUI Test
TDD With YUI Test

YUI Test is the test framework for Yahoo’s User Interface library. It is used by Yahoo to test its own library, and has syntax similar to jUnit.

Like jsUnit, YUI Test comes with its own logging console that can output info, warnings and errors in addition to the results of each test.

YUI also provides the ability to send reports on the results in either JSON or XML format.

YUI Test is BSD Licensed.

Pros
- Really good documentation
- Active community
- Regular releases
- Syntax is similar to jUnit (test suites, asserts and setup/teardown)
- Asynchronous support
- Good for DOM testing
- Tests always run sequentially in the order they are added to a suite

Cons
- Automation not trivial to implement,but less difficult than other frameworks

查看更多
迷人小祖宗
4楼-- · 2019-01-29 22:24

Also check out http://sinonjs.org/

Test spies Test stubs Mocks Fake timers Fake XHR Fake server Sandboxing Assertions

It does work along with qUnit and that has been a plus so far.

查看更多
太酷不给撩
5楼-- · 2019-01-29 22:25

I use the Screw Unit test framework and I've written my own mocking library called jsMocha which has been in heavy use in the company I work at for over 6 months.

查看更多
贪生不怕死
6楼-- · 2019-01-29 22:25

CrossCheck seemed extremely powerful when I looked at it, but we've not incorporated it into our build process at this time. It has the advantage of being browserless, and thus should work well in an automated build-and-test scenario.

http://thefrontside.net/crosscheck

查看更多
走好不送
7楼-- · 2019-01-29 22:27

You could try HtmlUnit which had a JQuery compatible release over a year ago.

The advantage of HtmlUnit is that it isn't driving a browser so it is FAST.

The downside is that it isn't driving a browser so there are some JS things that won't work. But offsetting that they can run the JQuery tests so the JS support might be good enough for what you need.

查看更多
登录 后发表回答