RESOLVED FIXED 69409
[GTK] [WebKit2] Make adding another unit test easier
https://bugs.webkit.org/show_bug.cgi?id=69409
Summary [GTK] [WebKit2] Make adding another unit test easier
Martin Robinson
Reported 2011-10-05 03:09:21 PDT
The GLib testing framework is a bit verbose and it's difficult to share fixtures between test files. This bug tracks adding a bit of C++ sugar to creating unit tests.
Attachments
Work in progress patch (41.92 KB, patch)
2011-10-05 03:12 PDT, Martin Robinson
no flags
Another approach based on martin's (32.74 KB, patch)
2011-10-05 08:22 PDT, Carlos Garcia Campos
no flags
My patch updated to fix run-gtk-tests (43.00 KB, patch)
2011-10-05 09:05 PDT, Martin Robinson
no flags
Patch (50.09 KB, patch)
2011-10-10 17:16 PDT, Martin Robinson
no flags
Patch (50.25 KB, patch)
2011-10-10 22:08 PDT, Martin Robinson
no flags
Martin Robinson
Comment 1 2011-10-05 03:12:41 PDT
Created attachment 109767 [details] Work in progress patch
Carlos Garcia Campos
Comment 2 2011-10-05 08:21:01 PDT
Comment on attachment 109767 [details] Work in progress patch View in context: https://bugs.webkit.org/attachment.cgi?id=109767&action=review I like the idea of making test easier to write, I have some comments, though. > GNUmakefile.am:211 > +include Source/WebKit2/UIProcess/API/gtk/tests/GNUmakefile.am Why adding a new makefile for the tests? > Source/WebKit2/UIProcess/API/gtk/tests/GNUmakefile.am:4 > +TEST_PROGS += \ > + Programs/WebKit2APITests/TestWebKitWebContext \ > + Programs/WebKit2APITests/TestWebKitWebView \ > + Programs/WebKit2APITests/TestWebKitWebLoaderClient Renaming the path and test names would break the bots, see bug https://bugs.webkit.org/show_bug.cgi?id=68992. so I would leave current names unless there's an important reason to rename them. > Source/WebKit2/UIProcess/API/gtk/tests/GNUmakefile.am:35 > +noinst_LTLIBRARIES += Libraries/libWebKit2APITestCore.la This library should probably be in WebCore or Tools, so that it can be used for wk1 tests too. > Source/WebKit2/UIProcess/API/gtk/tests/GNUmakefile.am:38 > + Source/WebKit2/UIProcess/API/gtk/tests/LoadTrackingTest.cpp \ > + Source/WebKit2/UIProcess/API/gtk/tests/LoadTrackingTest.h \ These files are specific to the loading test, I think there should be only common classes in the library, since all tests will link ot it. > Source/WebKit2/UIProcess/API/gtk/tests/TestWebKitWebLoaderClient.cpp:27 > +#include "config.h" > + > +#include "LoadTrackingTest.h" > +#include <gtk/gtk.h> > +#include <libsoup/soup.h> > +#include <wtf/text/CString.h> > + I don't mind using C++ for unit tests, but I'm not sure about using internal API in the tests. I think tests should only use public gtk+ api.
Carlos Garcia Campos
Comment 3 2011-10-05 08:22:27 PDT
Created attachment 109797 [details] Another approach based on martin's I think we can make it even simpler, we don't need a library, just a header file with a couple of macros.
Martin Robinson
Comment 4 2011-10-05 08:45:41 PDT
I think I prefer my original approach in the end for a few reasons: 1. Having a generic fixture means that we can apply logic before and after all tests in all suites. The logic for the test path isn't duplicated in multiple places. 2. I think it's important that we push the most common fixtures now to other files so that they can be used in more than one place. If necessary simple fixtures can be kept inline near tests. For an example, I could have easily extended the LoadTrackingTest fixture to also load alternate HTML when a failure happens. Then I could have used that fixture for multiple tests. This test probably belongs in TestWebKitWebView anyway. In the second patch we have to duplicate the WebView and main loop creation. Seeing this in every single WebKit1 unit test file is one of the main reasons I set out to do this. We get to use the C++ class system to our advantage. 3. I think we should avoid having the main method as a macro. I dislike macros in general, and perhaps I'll look for a way to implement this via templates. 4. I renamed the test files to better match the other files in the source tree. I believe we should use WebKit naming conventions everywhere possible. The only other binaries we produce that are named like this are the WK1 tests. I'm not sure it makes sense in this case. I'll upload a new patch which fixes build-webkit as well.
Martin Robinson
Comment 5 2011-10-05 08:47:38 PDT
(In reply to comment #4) > I'll upload a new patch which fixes build-webkit as well. Sorry, I mean run-gtk-tests.
Carlos Garcia Campos
Comment 6 2011-10-05 09:02:17 PDT
(In reply to comment #4) > I think I prefer my original approach in the end for a few reasons: > > 1. Having a generic fixture means that we can apply logic before and after all tests in all suites. The logic for the test path isn't duplicated in multiple places. There's a generic fixture in my patch too with methods begin and end to do whatever before and after tests. > 2. I think it's important that we push the most common fixtures now to other files so that they can be used in more than one place. If necessary simple fixtures can be kept inline near tests. > > For an example, I could have easily extended the LoadTrackingTest fixture to also load alternate HTML when a failure happens. Then I could have used that fixture for multiple tests. This test probably belongs in TestWebKitWebView anyway. That's possible with my patch too, you can just add a new fixture for loading tests and make loader client fixture inherit from it. I merged them just to avoid having an unnecessary library and to make the patch simpler and smaller. > In the second patch we have to duplicate the WebView and main loop creation. Seeing this in every single WebKit1 unit test file is one of the main reasons I set out to do this. We get to use the C++ class system to our advantage. You are assuming all tests using a web view have a main loop too. > 3. I think we should avoid having the main method as a macro. I dislike macros in general, and perhaps I'll look for a way to implement this via templates. I guess it's a matter of taste, I like macros :-) > 4. I renamed the test files to better match the other files in the source tree. I believe we should use WebKit naming conventions everywhere possible. The only other binaries we produce that are named like this are the WK1 tests. I'm not sure it makes sense in this case. I'll upload a new patch which fixes build-webkit as well.
Martin Robinson
Comment 7 2011-10-05 09:05:21 PDT
Created attachment 109808 [details] My patch updated to fix run-gtk-tests
Martin Robinson
Comment 8 2011-10-05 09:09:28 PDT
(In reply to comment #6) > You are assuming all tests using a web view have a main loop too. This is the case in almost all of the WebKit1 unit tests. I think it will be even more likely now because more operations will need to be asynchronous in WebKit -- for instance getting page content. I also believe this will help us organize our tests by what unit they go with, versus what fixture they need. I'm confidant that a more hierarchical design will make the barrier to adding a unit test smaller by allowing code reuse and reducing the noise in each test file. I think it's very important to make adding a unit test as easy as possible so we no longer shudder at having to write them.
Martin Robinson
Comment 9 2011-10-05 20:12:20 PDT
Carlos, I examined your patch again and I think it is not not so different from mine. I see a few main differences: 1. main() is inside a #define and depends on the fact that a test suite can only use one type of fixture. 2. Tests are embedded in the fixtures. 3. The files use their original names. Number 3 is not so important to me, but I do believe we should name the tests after the API they test - testloading -> testwebloaderclient, etc. Number 1 and 2 are pretty important to me though. Fixtures should be independent of tests, we should be able to share them between suites and suites should be able to mix and match fixtures. That's the main reason I wanted to do this. Perhaps we can reach some sort of compromise on the rest?
Carlos Garcia Campos
Comment 10 2011-10-05 23:40:36 PDT
(In reply to comment #9) > Carlos, I examined your patch again and I think it is not not so different from mine. I see a few main differences: Yes, as I said, my patch is based on yours. > 1. main() is inside a #define and depends on the fact that a test suite can only use one type of fixture. > 2. Tests are embedded in the fixtures. > 3. The files use their original names. > > Number 3 is not so important to me, but I do believe we should name the tests after the API they test - testloading -> testwebloaderclient, etc. > > Number 1 and 2 are pretty important to me though. Fixtures should be independent of tests, we should be able to share them between suites and suites should be able to mix and match fixtures. That's the main reason I wanted to do this. Perhaps we can reach some sort of compromise on the rest? Ok, I just wanted to avoid having another library if it is not really needed, and I didn't like having the main() in the library and the beforAll() afterAll() methods, I think we can have a class where befor/fater is just the constructor/destructor. But anyway, I don't want to block all new patches on this, and I agree on the idea of making adding new tests easier, so if xan and kov like your proposal it's fine with me.
Martin Robinson
Comment 11 2011-10-10 17:16:59 PDT
Martin Robinson
Comment 12 2011-10-10 22:08:50 PDT
Martin Robinson
Comment 13 2011-10-10 22:09:41 PDT
(In reply to comment #12) > Created an attachment (id=110472) [details] > Patch I updated the patch to fix some style issues and disconnect handlers signal destruction.
Gustavo Noronha (kov)
Comment 14 2011-10-11 11:15:08 PDT
Comment on attachment 110472 [details] Patch This shall make us able to set aside laziness and add unit tests more often =)
Martin Robinson
Comment 15 2011-10-11 21:20:09 PDT
Note You need to log in before you can comment on or make changes to this bug.