android - How to Mock/override/invoke CordovaPlugin's execute Method? -
i developing custom cordova plugin in android. other plugins - plugin consists of exposed js api android classes gets invoked when plugin js api called javascript.
now write junit or instrumentation tests native android plugin code.
below 1 main class in plugin gets invoked js support cordova
public class mainplugin extends cordovaplugin { @override public void initialize(final cordovainterface cordova, final cordovawebview webview) { super.initialize(cordova, webview); } @override public void ondestroy() { super.ondestroy(); myaction1.cleanup(); myaction2.cleanup(); } @override public boolean execute(string action, jsonarray args, callbackcontext callbackcontext) { if (action.contains("action1")) { myaction1.getinstance(cordova).executeaction(action, args, callbackcontext); } else if (action.contains("action2") ) { myaction2.getinstance(cordova, webview).executeaction(action, args, callbackcontext); } else { mcallbackcontext.error("action undefined"); return false; } return true; } }
as see
public boolean execute(string action, jsonarray args, callbackcontext callbackcontext)
method, invoking internal plugin classes actual job , send response.
my plan test internal classes mocking/invoking mainplugin's execute method. internal classes heavily depend on string action, jsonarray args, callbackcontext callbackcontext
, calls third party libraries. i.e need these parameters actual values or default values passed unit test code test internal logic.
please me code/suggestions, best way test myplugin internal classes. there lib mimic cordova behavior , able invoke excute
method java test code
Comments
Post a Comment