So far in this series, we've looked at buildless testing, an overview of testing approaches, and how to write unit tests. Today, let's talk about how to organize your tests! Split tests upWhen you're testing just one library, class, or chunk of code, you can keep everything in one test and one HTML file and get on just fine. But if you're working with a larger code base or testing lots of things, its a good idea to split the tests up, for a few reasons…
Tests should be easy to work with and fast to run, or you're less likely to use them! Naming conventionsA common convention is for each library or class to get its own test file that includes the word In addition to this naming convention, many code bases put all of the test files in a Because we're using a buildless setup here with HTML files, you might use the same naming convention for the test HTML files. Alternatively, you could include the test scripts directly inline in the HTML files, but that would potentially make it harder to run a CI process against your tests if that's something you'd like to do. Organizing assertions inside a test fileMost testing libraries also provide a way for you to organize and group assertions within a test file. In Mocha, the testing library we're using in this series, that's the
Our We might use
You can also nest one
When the test runs, it generates headings and subheadings that make the test output easier to read. If you were to run your tests using the command line, you would see a similar structure and output in the Terminal UI. What's next?You can download the source code for this tutorial on GitHub. Tomorrow, we'll look at TDD and how we can use it write better code, faster. And next week, we'll talk about code coverage, implementation details, and why neither of them really matter. We'll also look at some ways to test DOM manipulation libraries. Cheers, Want to share this with others or read it later? View it in a browser. |
0 Komentar untuk "[Go Make Things] Organizing JavaScript tests"