Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I structure TDD in Node.js?

I have my folder structured like:

backend
   |-Process1
   |-Process2
   |-app
      |-config
      |-controllers
      |-models
public
   |-css
   |-js

Where should I put my unit tests folder?

like image 522
Shamoon Avatar asked Dec 15 '11 23:12

Shamoon


People also ask

What is TDD in Nodejs?

Test driven development(TDD) is an iterate process that begins with writing a test code for an application or function before starting out to write the application. The next steps entails writing and refactoring the application until it passes the test code.

Which framework is needed for TDD?

The tools (or frameworks) used in TDD involve JUnit, TestNG, NUnit, etc. These are used to run test cases. Gherkin is used for writing scenarios in BDD. Cucumber, SpecFlow, etc., are some of the widely used test automation frameworks.

How do you write TDD in unit testing?

One Functionality, One Test: TDD is a form of Unit Test. The driven in the TDD means that to write code, you need to write the test first. And the best way to do is by focussing on only single functionality. Create a test that focuses on only one cause but sometimes one test is not enough.


1 Answers

For node projects, it's common to have a tests folder in the top level. For example, for my projects I usually have these folders:

  • bin (for bins)
  • lib (for my node.js library files)
  • test (for tests)
  • config (for config files, if necessary)
  • public or static (for static assets, if necessary)
  • node_modules (where npm-installed modules end up going)

For the most part it's not too critical how you organize the code as long as it's organized and has obvious entry points. Basically, you should be able to type "npm test" and have it work by reading the command from the package.json.

like image 153
Josh Holbrook Avatar answered Oct 02 '22 17:10

Josh Holbrook