9 Replies Latest reply on Mar 5, 2012 4:56 AM by lfryc

    Qunit integration tests

    wesleyhales

      Trying to find a way to run better qunit tests for the restful services, validation, etc...

       

      The first approach I'm trying is to simulate the user registering through the UI with input and click events. I'm creating an iframe which loads the page to be tested, then creating a no-conflict jquery object and using the jquery within the iframe to do the events.

      https://github.com/wesleyhales/as-quickstarts/blob/c57c542be8f63051517e7c5d2312461b61033d08/kitchensink-html5-mobile/src/main/webapp/js/qunit/index.html

       

      It's still a a work in progress, and wondering if selenium might do better with this. Any thoughts on best way to do the integration tests?

       

      Also, I had to move the tests into the webapp so that it can be deployed with the live site. Otherwise you get cross domain errors. We could use JSONP but I think CORS sttributes only exist on img and video.

       

      Thoughts?

        • 1. Re: Qunit integration tests
          jbalunas

          Lets talk more about this tomorrow at the team meeting, but I want to be careful to scope the work for the quickstart.  We want to show some good ways to get started with qunit, and validating basic aspects of the JavaScript, and Dom.  I'm not sure moving into integration testing is in that scope - at least for the quickstart. 

           

          I do think that selenium is likely the best way to move from unit testing to integration testing.  I'm not sure about the idea of the iframe, but I'll have to review more when we have time. 

           

          It might make sense to hold off on too many more qunit updates until Kris can take a look next week.  I believe he has some good experience here through jQuery UI.  I also know that Lukas has been doing work around JavaScript testing and integrating in to arquillian - JavaScript testing integration so he might be another one we can talk to about this.  For the quickstart however we might want to keep it simple enough to grasp the concepts quickly.

          • 2. Re: Qunit integration tests
            wesleyhales

            I think you already stubbed this out as a TODO?

            https://github.com/aerogear/as-quickstarts/blob/master/kitchensink-html5-mobile/src/test/qunit/test/test.js

            It made sense to have better tests with the jQuery upgrade. It should have actually been handled when the project was created - but I know you were short on time.

             

            Jay Balunas wrote:

            It might make sense to hold off on too many more qunit updates until Kris can take a look next week. 

             

            I won't worry about testing the code anymore at this point.

            • 3. Re: Qunit integration tests
              wesleyhales

              Jay Balunas wrote:

              I'm not sure about the idea of the iframe, but I'll have to review more when we have time.

              http://docs.jquery.com/QUnit#Further_tutorials

              http://michelgotta.posterous.com/user-interfaces-and-unittesting-with-qunit-an

              • 4. Re: Qunit integration tests
                jbalunas

                Thanks for this links.

                • 5. Re: Qunit integration tests
                  kborchers

                  In this case, I would not recommend the iframe approach. There is too much going on with that page to run effective tests and you want to simplify your tests down to basic functionalites so you know exactly what is breaking.

                   

                  Testing the HTML5 validation will be hard if not impossible since not all browsers support it so you'll want to stick to testing the other validation. To do that, I would just set up a simple form that mimics the user form and test with that. The iframe is probably a bad idea because your validation is happening asynchronously so you'll need to use asyncTest in QUnit and probably some other event capturing to get a proper test and doing that within the iframe just gets messy.

                   

                  I would be happy to take a stab at writing some of our initial tests if you would like.

                  • 6. Re: Qunit integration tests
                    jbalunas

                    I think it would be great if you could take a look at updating the qunit tests, and provide any comments, updates, etc...  Please create a sub-task for AEROGEAR-120 to cover updating the qunit tests for the quickstart.

                     

                    For the AS-* quickstart just remember the priority is introducing the technology and getting new users to see the value, base functionality, etc...  For the AeroGear specific examples we can get more in depth.

                    • 7. Re: Qunit integration tests
                      lfryc

                      The work to make Arquillian run QUnit tests is currently focused on plain runner for QUnit tests, without any integration with server side

                      but still integrated to Arquillian ecosystem - thanks to Drone - the Arquillian's Selenium runner - QA does not need to configure browser pool twice for Selenium and QUnit tests.

                       

                      But what may be interesting for you, we want to allow tests to cover app from client to server and back (doing validation / assertions on both sides).

                      This concept could use potentionally any client automation tool (Selenium / HtmlUnit / HttpUnit) and assert validations in potentionally any UI technology which have right hooks into own lifecycle (like JSF phase listeners) which could be registered by tested application. Still, we are targetting Java, because assertion objects needs to be enhanced by Arquillian.

                       

                      Arquillian also enables testing on Android emulators (Alpha1 released), which helps you to avoid usage of real devices in QA Labs.

                      Selenium itself has nice API for using Touch interface and also accessing HTML5 APIs like WebStorage from within Java API.

                       

                      So all over, for integration/functional tests I would recommend Selenium,

                       

                      however JavaScript code needs to be covered with unit tests (QUnit)

                      and thus for testing plain JS interfaces, I would use probably mocking approach (I have not tried yet, but I'm big fan of Java-version of Mockito, so I would try: http://jsmockito.org/).

                       

                      With some custom work, you could even mock the REST end-point "triggered by AJAX" without any server round-trip (pure client-side) -

                      it could be nice framework. ;-)

                      • 8. Re: Qunit integration tests
                        wesleyhales

                        Nice Lukas!! I expect to see this "framework" in your github repo I will make some PRs...

                        • 9. Re: Qunit integration tests
                          lfryc

                          Ah, it would be really nice prototype something like that, but it's currently out of my focus. :-)

                           

                          However with all other mentioned techs, you could count with me.