Question

I'm using Mocha Library and the Library by default use a Test folder. So, I have to copy the code I written in production into Test folder when doing Unit Tests with Mocha.

Anyone can think reason behind this method? Is it appropriate?

I'm just a hobbyist, haven't done programming for large companies. I also avoided unit tests thru Mocha for years but it seems it's right time for me to actually start to use Mocha to remove manual testing pain.

EDIT: Actually, I can import the code directly from Production but the practice among examples I witnessed is to use dedicated folder for Unit Tests, I looking to understand reasons behind this practice.

Was it helpful?

Solution

It's normal to keep tests in a separate directory because they are not part of the code that would be deployed. But it's also standard practice to import the code you want to test into the test code, without copying any code around.

For illustration, I opened up a random test from Mocha.JS' own test suite, and it does this:

var Mocha = require('../../lib/mocha');
Licensed under: CC-BY-SA with attribution
scroll top