Technology Blogs by Members
Explore a vibrant mix of technical expertise, industry insights, and tech buzz in member blogs covering SAP products, technology, and events. Get in the mix!
Showing results for 
Search instead for 
Did you mean: 
Product and Topic Expert
Product and Topic Expert
There has been a lot of buzz lately around using abap unit test and CI etc etc etc. I'm here to show a bit of a different approach to doing CI for your Odata development. What is my incitement for doing this?

Well truth be told, I'm not very good at Abap. Shh don't tell anyone.

As I have a lot of ground to cover i'll split up the content into three blogs. I'll add the links as I get them written.

  1. Using Postman for Odata development

  2. Using environment and variables in Postman [Since have already covered environment and variables in this blog. I won't repeat his.]

  3. How to record http requests to be used in Postman

  4. Using Postman collections in your CI

Stick tight and we will have some fun here.

So what is postman, well I'm not talking about this fella, that's for sure.

Postman is a test client for API development. As here's a bombshell for you. An Odata service is an API! ?

So why would you want to use postman for this? Well it's really simple to add these requests into Postman and write simple tests to validate whether you get the expected result. This way you aren't depending on a UI for testing if your Odata service behaves as expected.

Alright let's get to it!

Firstly you need to download postman, there is a Chrome extension and a native app. For now download the native app. The API for writing the test scripts differs a bit, so the native is what i'm using.

I'll be using the ES5 system for creating these OData tests as I'm too lazy to develop a new service and it really isn't the purpose of these blogs anyway.

First let's build a simple get request.

When you launch postman you will be presented with this screen.

I will cover the requests, collection and environment in this blog series. To begin we will create a simple request, so just select that.

When you press that you give a name and description and create a collection called GW_Basic. The collection is basically a group of requests, that's all you need to know for now. Hold your horses tiger, it will come.

Now as soon as you've saved that you are in the request screen. Add the following URL:$top=10

There is a few things to understand here:

  • Next to the URL, you see the http method. Keep it as GET for now

  • Params: This is where you add different parameters as key value pair (Or you can just add it directly in the URL

  • Authorization: Add your user name and password here as basic auth. As soon as you add it, a Header will be created for you.

  • Headers: Add adidtional header values here if needed

  • Body: Used for your POST and PUT calls

  • Pre-request scripts: Javascript code to be executed before your call is executed

  • Tests: Add test validations for when you execute your call

After you've added your username and password, press the send button and you should now see the XML in the response.

Alright now for the next bit, we can now add a test to validate the the result is as expected. Click the Tests tab.

In the right hand side, you'll see various snippets you can use. For our call here, we expect to have 10 sales orders returned and the status code to be 200. So let's code for that.

Firstly find the snippet Status code is 200 and press that. Et voila you've created your first test. If you press the send button again, you'll see the test results is now 1.

And if you click it you should see the following

Next we need to check that we actually have 10 orders returned. First click the snippet Response Body: Convert XML to JSON

Next we need to use the PM.test assertion to validate the result.
pm.test('We have 10 Sales orders', function() {
pm.expect(jsonObject.feed.entry.length === 10);

The jsonObject is our converted XML. In the conversion it is added to feed and the entry is the entries from the result. You can use console.log(jsonObject) as you would in Javasscript to append to the console. The Postman console view is available under the View menu.


Now save your request and it will be saved in your collection. Click the collections tab in the left hand side and find our GW_BAsic collection.


When you hover over it you will find a play icon.

Press that and afterwards press run. Postman will now execute all the requests and test scripts added to that collection.

Now you can re execute all these tests as often you want and add new requets to the collection to validate your new created code and also that you haven't messed up your existing code.

Happy testing.
Labels in this area