admin管理员组文章数量:1277888
I love qUnit for JavaScript unit testing, and have successfully used it for a large web hosting platform that is almost exclusively AJAX. However, I have to run it in a browser by hand, or as a Windows scheduled task, which is not ideal.
Has anyone run jUnit tests as part of an automated test suite, like you would in (say) perl or Java?
I love qUnit for JavaScript unit testing, and have successfully used it for a large web hosting platform that is almost exclusively AJAX. However, I have to run it in a browser by hand, or as a Windows scheduled task, which is not ideal.
Has anyone run jUnit tests as part of an automated test suite, like you would in (say) perl or Java?
Share Improve this question edited Jul 11, 2012 at 18:42 pb2q 59.6k19 gold badges150 silver badges152 bronze badges asked Dec 17, 2010 at 9:46 HogsmillHogsmill 1,57414 silver badges21 bronze badges2 Answers
Reset to default 7The simplest way could be running qUnit test with Selenium 2, from JUnit test. Selenium 2 opens webpages in Firefox, IE, Chrome or its own HtmlDriver and can do almost everything with a rendered page, especially with qUnit test results.
import static org.junit.Assert.*;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
public class FooTest {
static WebDriver driver;
@BeforeClass
public static void setUpBeforeClass() throws Exception {
driver = new FirefoxDriver();
}
@AfterClass
public static void tearDownAfterClass() throws Exception {
driver.close();
}
@Test
public void bar() throws Exception {
driver.get("http://location/of/qUnitTest");
//Handling output could be as simple as checking if all
//test have passed or as pound as parsing all test results
//and generating report, that meets your needs.
//Code below is just a simple clue.
WebElement element = driver.findElement(By.id("blah"));
assertFalse(element.getText().contains("test failed"));
}
}
I would remend jstestdriver. It allows you to run tests against real instances of browsers but from the mand line, which means it can be used in a CI build or simply run as part of your build script.
It has it's own assertion framework, which I have found to be better than qUnit. However, if qUnit is required for some reason then there is a plugin that allows you to write qUnit tests for the jstestdriver runner.
本文标签: Using qUnit for Javascript testingStack Overflow
版权声明:本文标题:Using qUnit for Javascript testing - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741244590a2364629.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论