How to write unit tests for server side Meteor code? - unit-testing

I have some server side code -- meteor methods and simple backend helpers -- that I would like to test. I've read the documentation testing with Meteor, but I am having a hard time connecting the documentation to my very simple use case. Can someone share with me how they've tested a meteor method or a simple backend JS function?
For instance, let's say you have some server method in, some_methods.js
function someHelper() {
// does lots of cool stuff
};
Meteor.methods({
'user/update' (userProperties) {
// updating some user properties
someHelper();
}
})

We have developed unit and integration tests for our open source application called RadGrad (https://radgrad.org).
For details on how we do unit and integration testing, please see:
https://www.radgrad.org/docs/developer-guide-testing.html
Here is an example of a unit (server-side only) test:
https://github.com/radgrad/radgrad/blob/master/app/imports/api/career/CareerGoalCollection.test.js
And here is an example of an integration (client + server) test:
https://github.com/radgrad/radgrad/blob/master/app/imports/api/career/CareerGoalCollection.methods.app-test.js
We do not have extensive UI tests; you'll need to use something like Selenium for that. UI testing in Meteor is no different from UI testing for any other web app.

Related

Framework for E2E tests akka-http

Asking this question because I am trying to figure out the framework which is most widely used for integration testing akka-http. How to automate those tests in Jenkins? Probably a rookie question but ideas are appreciated. Thanks
EDIT from comments:
What have you tried so far? So far I tried implementing 1. Jest 2. Using Testkit, IntegrationPatience Where are you stuck? Both the approaches doesn't look like standard to me and since I have app deployed in multiple locations, I am trying to understand if there is any framework out there which I can use to setup. The app is deployed to multiple data centers which may have different environment variables.
There are a bunch of ways to test a microservice developed using akka-http:
Unit testing
Functional / Integration testing
E2E testing
Load testing
Unit testing using route-testkit (https://doc.akka.io/docs/akka-http/current/routing-dsl/testkit.html)
Functional testing & E2E testing using Akka HTTP client API (https://doc.akka.io/docs/akka-http/current/client-side/index.html) with API contracts you can validate the status codes and response body.
Load testing can be achieved using a bunch of tools, specifically in Scala you can take a look at Gatling.

How to unit test ML.NET prediction?

I have a ML.NET project deployed as a web api like this - https://learn.microsoft.com/en-us/dotnet/machine-learning/how-to-guides/serve-model-web-api-ml-net
How do I mock the PredictionEnginePool, MLContext or the PredictionEngine in xUnit or any unit test framework?
Have you looked at the tests for ML.NET? MLContext is shown in those examples.
https://github.com/dotnet/machinelearning/tree/master/test
PredictionEnginePool (I don't believe is shown), but it is not a special construct that can't be tested. I would test the FileLoader and being able to test from remote locations if you have to.

How to write unit test for Ebean in play framework

I have an application based on play framework scala version 2.11.1.
There are couple of methods for which I want to add unit tests. These methods have direct calls to database through Ebean.
I tried with this link to use mocki-ebean in order to mock these calls. But the import was unsuccessful
I tried with powermock as well. but it requires to setup in-memory ebean server for mock calls. But that is also deprecated to setup in-memory server for unit testing.
Any idea what could be the next direction?

MobileFirst Adapters and Unit Test

IBM MobileFirst offers out of the box the possibility to invoke REST Services by server components written in plain Javascript, so called 'Adapters'. Since my app contains a lot of business logic inside them, I need to test it by Unit Test.
Could somebody suggest me a good framework how to create Unit Testing for 'server side' Javascript ?
Thanks.
You can write your own tests as mentioned in this post : https://mobilefirstplatform.ibmcloud.com/blog/2016/04/26/MobileFirst-adapters-automatic-testing/ .
Alternatively swagger UI and Postman can also be used as mentioned here : https://www.ibm.com/support/knowledgecenter/en/SSHS8R_8.0.0/com.ibm.worklight.dev.doc/devref/c_testing_adapters.html

How to unit test my Google OpenID consumer app?

My web app is a Google OpenID consumer (with Attribute Exchange and OAuth Extension) and I need to write some unit test for it [edit: to test the unit that is responsible to interact with google].
The problem is that default OpenID login procedure needs user interaction (entering user/pass) which is not possible in unit test.
Do you have any idea how can I solve this problem and unit test my OpenID consumer app?
(I prefer not to run my own OpenID provider.)
You need to use a remote controlled browser for this. Selenium was made for this use case.
(indeed they are called functional tests then).
Search on Google for the best way to integrate selenium tests into your web framework.
If I understand you want to test your all application and not just "unit test" it.
The actual test framework depends on the technology your application is using. For example there are many UI and web automation tools that can do what you want.
You should also unit test your core functionality or at least write several integration tests that work against an actual Openid provider but instead of running the entire application just test the functionality of the class (if you're using language that has classes) to make sure it can get the b.
I would also write a couple of unit tests that call a fake provider to test how your code behaves in case of error, connection problems and plain vanilla responses.