Skip to content
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions source/ja/faq/questions/general-questions-faq.md
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ No. There are already lots of tools to do that. Using Cypress to test against a

## {% fa fa-angle-right %} Is there code coverage?

There is nothing currently built into Cypress to do this. Adding code coverage around end-to-end tests is much harder than unit tests and it may not be feasible to do in a generic way. You can read in more detail about code coverage {% issue 346 'here' %}. You may find some other coverage utilities useful when writing end-to-end tests like:
Cypress supports code coverage via {% url "@cypress/code-coverage" https://github.com/cypress-io/code-coverage %} plugin. Read the official {% url "Cypress code coverage" code-coverage %} guide for details. We are also thinking how to go beyond code coverage, read the following blog posts:

- {% url "element coverage" https://glebbahmutov.com/blog/element-coverage/ %}
- {% url "application state coverage" https://glebbahmutov.com/blog/hyperapp-state-machine/ %}
Expand All @@ -138,6 +138,8 @@ We have internally experimented at doing DOM based component unit testing in Cyp

With that said - we actually believe the best form of testing in Cypress is a combination of a "unit test" mixed with an "e2e test". We don't believe in a "hands off" approach. We want you to modify the state of your application, take shortcuts as much as possible (because you have native access to all objects including your app). In other words, we want you to think in unit tests while you write integration tests.

See examples of Cypress running unit tests in the section {% url "Unit Testing" https://github.com/cypress-io/cypress-example-recipes#unit-testing %} of example recipes repo.

## {% fa fa-angle-right %} When should I write a unit test and when should I write an end-to-end test?

We believe unit tests and end-to-end tests have differences that should guide your choice.
Expand All @@ -154,7 +156,7 @@ In addition to the above differences, below are a few rules of thumb to decide w
- If the code you are trying to test is called from other code, use a unit test.
- If the code is going be called from the external system, like a browser, use an end-to-end test.
- If a unit test requires a lot of mocking and you have to bring tools like `js-dom`, `enzyme`, or `sinon.js` to simulate a real world environment, you may want to rewrite it as an end-to-end test.
- If an end-to-end test does *not* go through the browser and instead calls the code directly, you probably want to rewite it as a unit test
- If an end-to-end test does *not* go through the browser and instead calls the code directly, you probably want to rewrite it as a unit test

Finally, unit and end-to-end tests are not _that_ different and have common features. Good tests:

Expand All @@ -163,4 +165,8 @@ Finally, unit and end-to-end tests are not _that_ different and have common feat
- Give you confidence to refactor code and add new features.
- Are easy to run both locally and on a {% url "continuous integration" continuous-integration %} server.

Certainly, unit and end-to-end tests are NOT in opposition to each other and are complementary tools in your toolbox.
Certainly, unit and end-to-end tests are NOT in opposition to each other and are complementary tools in your toolbox. You can see examples of Cypress running unit tests in section {% url "Unit Testing" https://github.com/cypress-io/cypress-example-recipes#unit-testing %} of example recipes repo.

## {% fa fa-angle-right %} How do I convince my company to use Cypress?

First, be honest with yourself - is Cypress the right tool for your company and for a particular project? Implement a prototype to see how it feels to test a couple of common user stories, and if there are any technical blockers. Show the prototype to others before proceeding any further. We strongly believe that any new tools, like Cypress, spread faster by the "bottoms up" approach where people see how they solve their particular needs. If you show benefits of using Cypress to other engineers, if it truly is better than any other solution - then Cypress will be adopted and used widely.