Easwaramoorthy Kanagaraj
Easwaramoorthy Kanagaraj

Reputation: 4213

What is (best) way to unit test native part in cordova plugin?

The plugin folder will have only the source files of native code. In this case, just would like to know the (best) way to unit test native part in cordova plugin? Any idea would be appreciated.

Upvotes: 1

Views: 1007

Answers (2)

Tejas Dalvi
Tejas Dalvi

Reputation: 21

Maintain separate android project to unit test native code

  1. extract your plugins native java files in separate android library project in android studio
  2. write unit tests for java files in this android library
  3. after passing all testcases move this java files into plugin package

Upvotes: 0

daserge
daserge

Reputation: 1512

Add an additional plugin containing Jasmine tests, which will be calling your plugin interface (i.e. JS -> plugin proxy -> Native code), and then run it with cordova-paramedic.

Example test plugin:

mkdir test cd test npm install cordova-paramedic cordova-paramedic --platform windows --plugin ../your-cordova-plugin-name

You can then run tests for different platforms and even use SauceLabs for CI.

Upvotes: 1

Related Questions