Skip to Content

How to create automated testing SAP NodeJS

I searched all the web and github and there no samples how to approach automated testing for either CF MTAS app or CDS apps.
No documentation. No sample Code. Any ideas. I have been searching for 3 months now.

Add a comment
10|10000 characters needed characters exceeded

Related questions

2 Answers

  • Posted on Aug 05, 2020 at 06:11 AM

    Dear Salbador,

    I would suggest that you first get a clear picture what tests you want to execute:

    • Unit Tests
    • System Tests
    • Integration Tests
    • UI Tests

    When you follow the suggestion from Marius and use CAP for your development you can quite easy achieve Unit and System Tests including tests of the authorisations by running local tests with Mocked Authentication.

    For a full blow Integration Test of the deployed MTA on SAP CP Cloud Foundry you should follow SAP Cloud Platform Backend service: Tutorial [13]: API: called: from: external: tool.

    Regarding UI Tests I would suggest to do them also local as otherwise you always run into the authentication issues.

    And the Theia editor David and Thomas are using is the SAP Business Application Studio. And it's available in the trial account. I suggest you check out the tutorial Set Up SAP Business Application Studio for Development again. But I would recommend to go for local development with VS Code as it's way faster and you have more control.

    Best regards

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Aug 04, 2020 at 12:28 PM

    Hi Salbador,

    I'm sorry you had to look so long and couldn't find resources. I agree that there is not a lot of content out there. The good news is that there is no secret MTA/CAP-specific testing strategy out there. As both technologies build on open standards, you can use your favorite testing framework to automate it. You just need to start the CAP server via an API call and then you can start testing endpoints etc. Here are a couple of resources that go deeper in this:

    • I added a small testing part to the CAP Cities app that I wrote a while ago. You can find the project on GitHub.
    • The OpenSAP course about CAP covered this topic in Week 2 Unit 7 if you want to see a slightly different way of doing this.
    • The same OpenSAP course also has a unit that covers CI/CD (week4 unit 4)
    • And here is a community blog post that covers the topic.
    • MTA monorepos are quite flexible and you can include custom build command to trigger test suits if needed. I've done something similar in the past where I triggered a TypeScript compiler (instead of a test run)
    Add a comment
    10|10000 characters needed characters exceeded

    • Hi Marius,

      Thanks for the prompt response. I read and watched everything here. Most of it is CDS, except for your last topic where you talk about MTAs. I should mentioned more specifically. I am looking for a way to place a "before" to us with CF app and authenticate before mocha or jest. Seems, I understand the new promoted format for cf apps is APP, SRV, DB, folders. Where the APP folder, using @sap/approuter.js does all the magic to connect to HANADB and the SRV server.js routes.
      So, I want to test sending data to the server and back, the HANADB server, I will not be able to. Since, inside the CF SRV folder I could not be able to authenticate.
      I can place dummy functions with not authentication, but this will not have access to the HANADB service inside the cloud.

      For example, inside the SRV folder, if my app needs to access the DB declared inside the DB folder, (which you guys call wrongly "modules," --- should really change that too)
      to be able for SRV to access the created DB from the DB folder. Then these lines are required:

      app.use(passport.authenticate('JWT', { session:false }));
      With these lines. now the jest testing of any route will return forbidden. Since it would be missing the jwt token with the Bearer.

      But, since the newJWTStrategy, is a private sap repository. And since the approuter.js is using a modified version of passportjs inside of it. I am having a hard time figuring out how to get the token and pass it before each test.

      The most similar approach that I found is a xsjs app
      that I found is

      \---- srv/utils/tests.js:6
      which has a function called "getAuthToken: () => {"
      which is called inside only twice inside.
      \---- srv/tests/rest/secure-spec.js:14 .set("Authorization", "bearer " + awaitthis.test.getAuthToken())
      \---- srv/tests/rest/secure-spec.js:26 .set("Authorization", "bearer " + awaitthis.test.getAuthToken())


      There is no documentation of what is going on. The sample app found has no way of running it to test it. One has to imagine what is going on.

      Lost in imagination.

      Trying to port something similar to a pure CF app.

      Similarly, the appointed CDS samples that are provided in your list. Have no mention of security. It is somehow assumed.
      The bad part if that in that assumption is blocking for all the new ones. Like me.
      I cannot deploy a huge app. That an expert made, with expert comments on how to setup HANA this and HANA that.
      Most of the videos from David and Thomas. Are really slow and take a looooooooong time. And most of them are using the old platform, without the Theia editor, that is no longer available in the trial for the newbies.

      And I understand it. XSJS is the old way of doing NodeJs programming.
      So CF and CDS are the new ways?

      Perhaps I am very close to my answer. But I might a need push to figure it out.

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.