简体   繁体   中英

Integrating javascript unit tests in an existing webpage

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 solution 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM