How to run Dojo DOH unit-tests through Jenkins?

后端 未结 3 1372
北恋
北恋 2021-02-07 10:59

Has anyone tried integrating Dojo DOH unit-tests with Jenkins?

I\'d like to do the following, but don\'t want to reinvent it if this has already been done. So, I\'m think

3条回答
  •  一个人的身影
    2021-02-07 11:38

    Here's how I did it with HTMLUnit. No Selenium required.

    It runs as a regular JUnit test (which can easily be run automatically by your CI Server), and prints out the DOH log if there is a test failure.

    public class JavascriptTest {
    
      private static final int MAX_RUNNING_TIME = 10 * 1000;
    
      //The test runner
      public static final String PATHNAME = "src/main/webapp/library/mystuff/dojo/util/tests/runTests.html";
    
      //Runs all of the Dojo Objective Harness (D.O.H.) javascript tests.
      //The tests are currently grouped into test modules, and the parent module is "util.tests.module" (in module.js)
      //As you can see in the URL pathname, we pass that module name to the testRunner and it runs all the javascript tests.
      @Test
      public void runAllJavascriptTests() throws Exception {
        final WebClient webClient = new WebClient(BrowserVersion.INTERNET_EXPLORER_8);
        final HtmlPage page = webClient.getPage("file://" + new File(PATHNAME).getAbsolutePath());
    
        waitForTestsToRun(webClient, page);
    
        String log = page.getElementById("logBody").asText();
        assertTrue(log, page.asText().contains("WOOHOO!!")); //D.O.H. will display WOOHOO!! if all tests are successful.
      }
    
      private void waitForTestsToRun(WebClient webClient, HtmlPage page) {
        webClient.waitForBackgroundJavaScript(500);
        int runningTime = 0;
        while(testsAreRunning(page) && runningTime < MAX_RUNNING_TIME){
          webClient.waitForBackgroundJavaScript(500);
          runningTime += 500;
        }
      }
    
      private boolean testsAreRunning(HtmlPage page) {
        //Check if the "Tests Running" div is visible.
        return "".equals(page.getElementById("playingMsg").getAttribute("style"));
      }
    
    }
    

    And below is the content of runTests.html. It basically just redirects to the DOJO test runner, with parameters specific to the tests in the directory we want to test.

    It's just a nice way to structure things, you could alternatively have specified this URL in the PATHNAME field in the JUnit test.

    
    
        
        Dojox Unit Test Runner
          
          
        
        
            Redirecting to D.O.H runner.
        
     
    

提交回复
热议问题