DEVELOPERLESS API PORTAL

APIMATIC APIs

IN THIS ARTICLE

SHARE THIS ARTICLE

Testing Frameworks

Below, we will highlight some of the testing frameworks available per language. You can utilize these when making use of the test generation feature.

C#

For C#, you can either generate a Portable Class Library (PCL) or a Universal Windows Platform (UWP) library at the time of SDK generation.

The Portable Class Library (PCL) can run on range of platforms such as Windows, Silverlight and Windows Phone. In order to run the test cases generated along with the library, you require a testing framework. One such framework is “NUnit” whose current release version is 3.0. If you use Visual Studio you can easily install it using the Extension Manager.

After a successful build of the generated solution in Visual Studio, you can run the tests from the Test Explorer and a generated report will tell you various statistics including the number of tests that passed or failed.

The Universal Windows Platform (UWP) library also supports many of the Windows platforms including but not limited to Windows 10, Windows 10 Mobile, Xbox One etc. The unit testing framework you can use for running the test cases generated along with this library is MSTest. Just like NUnit, MSTest also allows the tests to be run from within Visual Studio.

Android

You can generate a gradle based Android library from your API description. You can then use it inside an IDE like Android Studio (that comes with Gradle) or a command line based gradle build system. An Android library compiles into an Android Archive (AAR) file that you can use as a dependency for an Android app module.

The generated tests are defined as JUnit tests. JUnit is the most popular and widely-used unit testing framework for Java. You can navigate from within Android Studio to run these generated tests which internally makes use of the Android JUnit runner. The tests are instrumented tests that run on the emulator/hardware.

Java

The generated Java SDK is actually a java library which can be used with JRE7. You can use an IDE like Eclipse equipped with Maven to utilize this library e.g. this Java library can be added as a dependency for a Java project.

To run the generated tests you require a testing framework. For Java, the most widely used framework is JUnit which not only acts as a framework but also as a runner. Inside Eclipse, you would need to select the library project and then choose to run the JUnit tests.

This will run all the tests present in the “tests” directory and display relevant statistics.

Objective C

Generation of SDK for IOS will generate a Cocoa Touch Static Library which is a static library in Objective-C. The advantage of generating a static library is that it supports iOS versions as old as iOS 6.

You can run the generated tests from within an IDE like “xCode”. It provides its users with capabilities for extensive software testing. It consists of a built-in test framework called “XCTest” which allows for smooth running of the generated tests.

PHP

When you generate an SDK for PHP you will obtain a php library that is based on PHP version 5.3 or greater and also requires Composer dependency manager. You can use this library as a dependency in your project. The test cases generated during SDK generation can be run using a testing framework like PHPUnit.

Python

SDK generation in Python results in a Python package compatible with Python 2.7.x and Python 3.x, which uses PIP as the dependency manager.

A famous testing framework is “unittest” which is python’s xUnit style framework. It is a test module that comes bundled with the Python standard library. “nose” extends “unittest” to make testing easier as it provides automatic test discovery. For our generated SDK, “unittest” is used as the testing framework and “nose” is used as the test runner. Invoking a simple command “nosetests” on the SDK will help run the tests.

Ruby

SDK generation in Ruby results in a Ruby Gem based on Ruby version 2.0.0 or greater. The tests automatically generated can be run using a testing framework like Test::Unit that includes the appropriate test runners.

NodeJS

SDK Generation in NodeJS creates a Node based library which can be included in the project. Dependencies need to be resolved by using npm. The SDK already comes with a package.json file which contains information about all the dependencies. Running npm install from the command line will resolve all dependencies.

For tests, Mocha is used as the testing framework. Mocha is coupled with Chai as the assertion library for tests. Mocha acts as the test runner for test cases generated with the SDK. Tests can easily be run from the command line by typing mocha --recursive from the SDK’s root folder.