@@ -523,9 +523,65 @@ Save and close in your editor. The first time you do this, you should be prompte
523
523
put in your username and password. Just use the same ones as your trac account.
524
524
525
525
526
+ = Unit Testing =
526
527
528
+ As of November 2007 we require all new features going into trunk to be accompanied with
529
+ a unit test. Initially we have limited this requirement to qgis_core, and we will extend
530
+ this requirement to other parts of the code base once people are familiar with the
531
+ procedures for unit testing explained in the sections that follow.
527
532
533
+ == The QGIS testing framework - an overview ==
528
534
535
+ Unit testing is carried out using a combination of QTestLib (the Qt testing library) and
536
+ CTest (a framework for compiling and running tests as part of the CMake build process).
537
+ Lets take an overview of the process before I delve into the details:
538
+
539
+ * '''There is some code you want to test''', e.g. a class or function. Extreme programming
540
+ advocates suggest that the code should not even be written yet when you start
541
+ building your tests, and then as you implement your code you can immediately validate
542
+ each new functional part you add with your test. In practive you will probably
543
+ need to write tests for pre-existing code in QGIS since we are starting with a testing
544
+ framework well after much application logic has already been implemented.
545
+
546
+ * '''You create a unit test.''' This happens under <QGIS Source Dir>/tests/src/core
547
+ in the case of the core lib. The test is basically a client that creates an instance
548
+ of a class and calls some methods on that class. It will check the return from each
549
+ method to make sure it matches the expected value. If any one of the calls fails,
550
+ the unit will fail.
551
+
552
+ * '''You include QtTestLib macros in your test class.''' This macro is processed by
553
+ the Qt meta object compiler (moc) and expands your test class into a runnable application.
554
+
555
+ * '''You add a section to the CMakeLists.txt''' in your tests directory that will
556
+ build your test.
557
+
558
+ * '''You ensure you have ENABLE_TESTING enabled in ccmake / cmakesetup.''' This
559
+ will ensure your tests actually get compiled when you type make.
560
+
561
+ * '''You optionally add test data to <QGIS Source Dir>/tests/testdata''' if your
562
+ test is data driven (e.g. needs to load a shapefile). These test data should be
563
+ as small as possible and wherever possible you should use the existing datasets
564
+ already there. Your tests should never modify this data in situ, but rather
565
+ may a temporary copy somewhere if needed.
566
+
567
+ * '''You compile your sources and install.''' Do this using normal make && (sudo)
568
+ make install procedure.
569
+
570
+ * '''You run your tests.''' This is normally done simply by doing '''make test'''
571
+ after the make install step, though I will explain other aproaches that offer more
572
+ fine grained control over running tests.
573
+
574
+ Right with that overview in mind, I will delve into a bit of detail. I've already
575
+ done much of the configuration for you in CMake and other places in the source tree
576
+ so all you need to do are the easy bits - writing unit tests!
577
+
578
+ == Creating a unit test ==
579
+
580
+ == Adding your unit test to CMakeLists.txt ==
581
+
582
+ == Building your unit test ==
583
+
584
+ == Run your tests ==
529
585
530
586
= Authors =
531
587
0 commit comments