nodejs unit test stubs with neo4j - node.js

Anyone know of a way to spin up a neo4j instance for testing?
We're using Nodejs + Neo4j, with minimal unit tests which I'd like to change.
NosqlUnit looks promising but its dependant on JUint to run.
The Neo4j class com.lordofthejars.nosqlunit.neo4j.InMemoryNeo4j sounds fantastic. But I cant find any info on Google or Stackoverflow. Could this potentially be invoked by Java or Scala while running my tests in Nodejs?
Any help hints tips or tricks welcomed.
Update
I think using nodejs & sails-memory is a good option. As the main concern is testing the application layer. Using the waterline orm will allow me to swap databases for testing purposes.

Related

Is there a better way to test Node.js application with ElasticSearch?

If use Ruby on Rails framework, we can run the test in a easy way. It can create a test database, and we can make some fake data. After all the test finished, the test database will be cleaned.
Now want to do the same test with Node.js, Express framework and ElasticSearch. If create index data in the real ES server, maybe not the good way(Think ES as development environment used). Is there a better way to do it as RoR above?
I have researched from internet, but didn't find good example.

elasticsearch embedded in Node.js

I am new on developing in Node.js, I would like to know if there's a way to have ElasticSearch embedded in a Node.js application for testing purposes or if there's another way to test interaction with ElasticSearch without having an ElasticSearch running instance (mock ?)
There are no existing mock libraries for Elasticsearch and Node at the moment. If you know exactly what queries you are going to be performing, you could use a mocking library to mock the entire ES client and assert simple behaviors.
What I'd recommend, however, is actually running ES in a development environment for testing. I find that mocking external services is a pretty tricky thing to do in general, and your tests will likely be much more robust / trustworthy if running against an actual instance of the server.

Automated testing node js and database

I'm using jenkins to automate the testing of my node js application? How do I test the queries to the database? How does Jenkins know to build the mongo db database first? How does automated testing work with database?
I don't use Jenkins for CI, I tend to use TeamCity, but I think your questions can be answered independently of which CI technology you use.
There is no definite answer to your questions, it all depends:
If you are looking to implement full integration tests, including querying a real database, then I would suggest creating a separate database just for testing like - mydb-test. You would have to configure your tests to use this database via config etc. In case you want to isolate your tests from the data access layer, then you need to mock the data access. This can be done by using a mock library, this will be easier to use depending on how well architected is your application code, where dependency injection IMHO is really important on this matter.

How to do load testing of node.js server?

I want to write one web application with node.js and MongoDB and I have got task to even test it. I would like to know if there are any tools like JMeter or anything else for load/stress testing of Node.js?
EDIT
My application is going to be information extraction kind of application and client expects extraction should not take more than 10 seconds for one document. Currently I have same application written in C# but its not scaling upto client's expectations. Then I came across this beautiful and fast Node.js. I think Node.js can help me alot.
Please enlighten !!!
Try nodeload: it's a collection of node.js modules for load testing HTTP services.
As a developer, you should be able to write load tests and get
informative reports without having to learn another framework. You
should be able to build by example and selectively use the parts of a
tool that fit your task. Being a library means that you can use as
much or as little of nodeload as makes sense, and you can create load
tests with the power of a full programming language. For example, if
you need to execute some function at a given rate, just use the
'nodeload/loop' module, and write the rest yourself
Just found out that this package is no longer under development so here are some active forks:
https://github.com/gamechanger/nodeload
https://github.com/Samuel29/NodeStressSuite
Why couldn't you test a node server with JMeter? For most load tests it doesn't matter what language your server is, you're just hitting it with a bunch of requests.
In any case, you could try loadtest which is implement in node.
Runs a load test on the selected HTTP or WebSockets URL. The API allows for easy integration in your own tests.
Edit:
This answer provides more options:
NodeJs stress testing tools/methods [closed]
Try artillery. Here are its features, the description of which is taken from the documentation:
Multiple protocols: Load test HTTP, WebSocket, Socket.io, Kinesis, HLS and more.
Scenarios: Support for complex scenarios to test multi-step interactions in your API or web app (great for ecommerce, transactional APIs, game servers etc).
Load testing & Functional testing: reuse the same scenario definitions to run performance tests or functional tests on your API or backend.
Performance metrics: get detailed performance metrics (latency, requests per second, concurrency, throughput).
Scriptable: write custom logic in JS, using any of the thousands of useful npm modules.
Integrations: statsd support out of the box for real-time reporting (integrate with Datadog, Librato, InfluxDB etc).
Extensible: write custom reporters, custom plugins, custom protocol engines etc.
and more! HTML reports, nice CLI, parameterization with CSV files.

Mock/Test Mongodb Database Node.js

I am learning nodejs and I have a mongodb database with which i have to interact with. I am currently thinking of using mocha for a unit test framework and zombie.js for a acceptance test framework. I was wondering how could I do full scale acceptance tests which hit the mongodb database. Is there a framework/module that helps with replacing the database with a test database or does either mocha or zombie.js have functionality that can easily be used to replace the database.
Also is there a framework that is similar to the idea of factories (instead of fixtures) in creating database objects.
A similar concept that I have encountered in the rails world is in rspec, there is a spec_helper.rb file which runs before the tests are run which set the projects configuration to decide which database to hit when running tests. And it uses database_cleaner to clean out the test database before tests are run. For factories, i have used Factory girl to create factory objects from database schema again in the rails world.
Thanks
If your database access is a separate module, you can mock out the module or parts of the module (e.g., the configuration part) using one of the following:
sinon
rewire
horaa
sandboxed-module
The answers to the following related question lists a number of possible solutions/approaches:
How do you mock MySQL (without an ORM) in Node.js?
In order to spin up a real in-memory mongodb for testing, https://github.com/nodkz/mongodb-memory-server helps as well.

Resources