The test case failed after introducing Nacos - nacos

My test cases (the test directory) have a dedicated configuration file (application.yml) and use the H2 database, while the business code uses the business database. When I introduced the Nacos configuration center (bootstrap.properties) in the business code, my test cases all went wrong. I suspect that there is a problem with the priority when reading the configuration file, but I have not solved it. I am looking forward to your help

Related

Unit, Integration and Functional Testing

I am working on Test Case and I would like to get clarity about which are the directories & files that come under,
Unit Testing.
Integration Testing.
Functional Testing.
My application architecture is as follows,
controllers (which controls the respective action by calling service file from services directory).
models (model for data tables).
routes (for routing).
services (a layer that communicates with model).
db (holds migration for the database).
index.js (which runs the server).
Could anyone help me out by saying which directories & files needs which type of testing (Unit, Integration, Functional)?
Thank you.
Unit tests: As the name suggests these tests cover separate units in your code, so each function/file should have it's own separate unit test(s). Also you don't use real network and database for these tests, they are stubbed/mocked.
Integration tests: These test working of different modules in integration with each other. Looking at your architecture, index.js and services seem to be the main modules and controllers, models and routes seem to be helper modules. So you would be writing tests for index.js and services against a real database and network with configurations same as your application in real life.
Funtional tests: These tests mimick end user experience and they are also called End to End test. These tend to be complex to write and not robust as the application changes over time. This entails writing something like selenium tests where all the browser clicks are automated and it is ensured everyhting displays as expected. I would suggest to write not to many of these and cover only main scenarios.

Testing express application with mongodb

I have a question regarding the different tests for a node and specifically an express application.
I am new to node/express coming from a PHP background, so have a few questions.
I know about unit testing, using things like PHPUnit, so I have read about about Jest. My specific questions regarding jest and unit testing in an application like express. Is should I be breaking my code apart more? It currently is quite together my routes are basically where all my business logic is found. Which means it's difficult to unit test?
Then with something else like end to end testing, I am looking at testcafe. For this I am really unsure how to get past my authentication and furthermore how to test on my local machine, before pushing code to production.
Full disclosure, I have a CI setup to my main branch, so I am looking to implement these tests to stop me merging breaking code to my master branch and breaking the production site.
Personally I always prefer mocha.js for testing any node app. It specifies how many test cases are passing, generates a report for those which are not passing. Also it specifies the time required to execute a code segment.
I'm also relatively new to node. I use the same stack as you (Express + MongoDB), applying MVC pattern. In Java I used to write a lot of unit tests with Spock, but right now I focus mostly on integration testing.
In my opinion routes should not contain any logic. Try to move it to separate layer - services. This way you can focus on testing logic provided by them, instead of trying to test code hidden in your routes.
For testing I use mocha.js, chai and chai-http.
My approach is to set up test database and form my tests as a sequence of requests. There is no problem with testing authentication that way - just need to correctly set up db with some user data. If you want to cut off the dependencies like database, use sinon for stubbing and mocking.
The obvious downside of this approach is testing time, but you can split tests into unit and integration suites. Run your unit tests locally and integration tests in your CI pipelines.
I'm not sure if it's the best approach, but I'm positive about the effects. Learning new technology means refactoring a lot. I have changed the structure of my project multiple times, moving logic, extracting methods and classes etc. Integration tests assure me that I haven't broken the business logic, despite having changed what's in the black box. This kind of breaking changes would be way harder to maintain with unit tests.

Testing File Streaming in Cucumber

Any idea how to test file streaming in Cucumber?
Note this is a Java microservice with a client and server architecture.
The client talks to the server on a designated port..I just dont know how to do this?
Most of the examples that I have seen are Browser Based Testing with Selenium.
I am writing Junit test cases for this and I wanted to know how this is to be done.
I am new to Behavior Driven Testing and I find this really exciting!
You have to imagine you are the client and that you are consuming the service. When you use the service what do you get back. If you are cukeing you need to think in business terms e.g. its about WHAT you are doing and WHY its important, not HOW its done. So WHAT is the point of this service, what value does it give.
If you just want to test that it works then I'd use a unit test tool instead.

Unit testing a python 3.x code written for Google AppEngine flexible environment and using Cloud Datastore Api

Is there a way to unit test a code which is using cloud datastore api and written for flexible environment? testbed seems to be tied up with standard environment and it looks like using emulator will require launching/closing emulator process which usually is a flaky way for unit tests.
We end up with end to end testing (launch you tests with real db in dev environment, for example) As we having tenant based application, each test run just creates new tenant and all operations performed in scope of this tenant, so, there should no any inconsistency here. In the other hand, such solution is pretty slow.
The solution above, is just the easiest one, I believe here.
Another option would be to split you code on db dependent parts and business logic part. In this case you will test only business logic part, and mock db dependency. But, as we've investigated such solution, we found that we have a lot of code that have one line of db write operation and 1-3 lines of business logic code. So, splitting such code on different levels would be meaningless for testing and maintenance.
I guess, the last option is more generic relatively previous one, is to mock db. For each module that uses db, before test it you should inject mocked database index, that defines some responses. But in this case it is easy to fall in realization testing, instead of behavioral testing, so again that will mean, that such testing becomes quite ineffective.
I guess, this question is more generic about testing approaches, and not about actually datastore itself.

BDD with Cucumber to guide Chef development

I like a lot Cucumber and I find a very useful tool to solve problems seeing them with an outside-in approach so I would like to use it as part of chef projects too. I have successfully integrated it into the project I'm working on but at the time of writing business goal of features I have some doubts.
Who is the end user here?
Regarding on this the feature will be more service oriented or not, ie:
If the feature is more architecture faced the I could write a MongoDB feature which describes that I need up and running a MongoDB service and that the applications is linked to it.
In the other hand I should just write application features, forgetting about the infrastructure behind and then assume that if the cucumber tests run well for the application then it means that the infrastructure is fine too. (I dont like this approach)
Which of the both approaches are better? I like the most the first one but I'm just a noob on these lands. Please give me your considerations.

Resources