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?
The 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 compound 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"));
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With