简体   繁体   中英

Unit Testing - test for file count and folder size


I have homework JS code to check every week.
I have tests for JS logic, but i also has a requirement for overall size and file quantity. So i was wondering is there any possibility to write tests (i assume mocha - because it runs on node, and has access to FS) for folder size and file count in folder (also has a limit)?

I have no experience in Mocha or Node, so should i dive deeper?

I'm not quiet sure what you are asking, but:

Mocha is a framework to run "unit tests" to test the software you have written and see if it's working ok.

If you just want to count some files in a directory you don't need a testing framework. Just use node's normal filesystem classes in fs https://nodejs.org/api/fs.html to write your code.

If you want to check that files maybe you are talking about integration test and not unit test. So, I believe that if you want to make unit test you will need read something about mock's and stub's. You can search modules like sinon. A few weeks I was fighting with test that checks if dirs or files are created and I reached the conclusion that if I want to make unit tests I need that module. Here's Sinon

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM