Skip to content

Instantly share code, notes, and snippets.

@amphro
Last active December 30, 2015 23:49
Show Gist options
  • Save amphro/7903186 to your computer and use it in GitHub Desktop.
Save amphro/7903186 to your computer and use it in GitHub Desktop.
A bookmarklet to run an org's namespace tests from the Developer Console To add a bookmarklet, go to the bookmark manager, add a new bookmark with a name of "Run NS Tests" and the following code as the URL. Then, open the Developer Console in a tab and click on the bookmarklet. The uncompressed code is here: https://gist.github.com/amphro/7903051
javascript:function runNamespacedTest(e){function r(e){if(console&&console.log)console.log(e)}function i(){Ext.Msg.alert("Running namespaced tests failed","Please look at the javascript console for more information.")}function s(e){if(e.length===0){Ext.Msg.alert("No tests enqueued",'No test found in namespace "'+n+'"');return}r("Enqueuing "+e.length+" tests");Ext.Msg.updateProgress(.6,"Enqueuing "+e.length+" tests");if(SfdcDevConsole.ToolingAPI.runTests){SfdcDevConsole.ToolingAPI.runTests({classids:e},{continuation:function(){Ext.Msg.close()},failure:i})}else{Ext.Ajax.request({url:"/_ui/common/apex/test/ApexTestQueueServlet",params:{action:"ENQUEUE",classid:e},success:function(){Ext.Msg.close()}})}}function o(e){var t=[];for(var n=0;n<e.length;n++){var i=e[n];var s=i.SymbolTable;var o=s.tableDeclaration.modifiers;var u=o.length;while(u--){if(o[u]==="TEST"){r("Found test: "+s.name);t.push(i.Id)}}}return t}function u(){SfdcDevConsole.ToolingAPI.query("SELECT Id, SymbolTable FROM ApexClass WHERE NamespacePrefix = '"+n+"'",{continuation:function(e){Ext.Msg.updateProgress(.3,"Finding tests classes via symbol tables");try{s(o(e.records))}catch(t){i();if(console&&console.error)console.error(t);throw t}},failure:i})}function a(){Ext.Ajax.request({url:"/_ui/common/apex/test/ApexTestQueueServlet",params:{action:"GET_TESTS"},success:function(e){Ext.Msg.updateProgress(.3,"Finding tests classes via internal servlet");try{var o=Util.evalAjaxServletOutput(e.responseText);console.log(o);var u=o.testClasses;var a=[];var f=t===n?"My Namespace":n;for(var l=0;l<u.length;l++){var c=u[l];if(c.ns.indexOf(f)>=0){a.push(c.id);r("Found test: "+c.name)}}s(a)}catch(h){i();if(console&&console.error)console.error(h);throw h}}})}var t=SfdcDevConsole.hasNamespace()?SfdcDevConsole.namespace:"";var n=e||t;Ext.Msg.progress("Running namespaced tests","Fetching apex classes");a()}runNamespacedTest();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment