开发者

Integrating javascript unit tests in an existing webpage

开发者 https://www.devze.com 2023-02-06 10:19 出处:网络
I have some javascript functions which I would like to test in the context of a webpage. To be clear, these javascript functions are closely coupled to that certain web-page. They manipulate all kinds

I have some javascript functions which I would like to test in the context of a webpage. To be clear, these javascript functions are closely coupled to that certain web-page. They manipulate all kinds of GUI related stuff on the webpage. So effectively I would like to unit-test my web-page and not just its JavaScript functions.

I would like to be able to test this functionality in the original webpage.

However, testing suites like QUnit require that I add some code to my page to start-up the test suite. The problem is that this new html web-page does not contain my code.

A trivial solutio开发者_C百科n would be to copy-paste my original html page into the test-suite page. This is a "filthy" solution which would require me to copy my html page into my test-suite-page each time.

In c++/java my test code would simply include/import my original code and do what it needs, but in HTML I lack a proper include statement.

What is the proper solution for this?


It seems like you're trying to perform a browser test, and not a pure javascript one.

Check if Selenium fits your needs. You can use it to interact with the page and check presence or absence of text, or to run javascript code in the context of the page and, again, check for effects.

0

精彩评论

暂无评论...
验证码 换一张
取 消