Sunday, May 12, 2024
9
rated 0 times [  14] [ 5]  / answers: 1 / hits: 54636  / 14 Years ago, wed, may 19, 2010, 12:00:00

Is there a good way to do this? I'm writing an extension that interacts with a website as a content script and saves data using localstorage. Are there any tools, frameworks, etc. that I can use to test this behavior? I realize there are some generic tools for testing javascript, but are those sufficiently power to test an extension? Unit testing is most important, but I'm also interested in other types of testing (such as integration testing).


More From » unit-testing

 Answers
15

Yes, the existing frameworks are pretty useful..



In the recent past, I have placed all my tests on a test page that was embedded in to the application but not reachable unless physically typed.



For instance, I would have all the tests in a page accessible under chrome-extension://asdasdasdasdad/unittests.html



The tests would have access to localStorage etc. For accessing content scripts, in theory you could test that through embedded IFRAMEs in your test page, however these are more integration level testing, unit tests would require you to abstract that away from real pages so that you don't depend on them, likewise with access to localStorage.



If you want to test pages directly, you can orchestrate your extension to open new tabs (chrome.tab.create({url : someurl}). For each of the new tabs your content script should run and you can use your testing framework to check that your code has done what it should do.



As for frameworks, JsUnit or the more recent Jasmine should work fine.


[#96734] Monday, May 17, 2010, 14 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
keyanah

Total Points: 642
Total Questions: 93
Total Answers: 114

Location: Virgin Islands (U.S.)
Member since Tue, Jul 7, 2020
4 Years ago
;