GNOME Bugzilla – Bug 735193
Unittests should be more granular
Last modified: 2018-01-10 20:45:20 UTC
A lot of our unittests are large functions which test multiple units. These should be broken down into small single function tests. The advantage of this is it makes it easier to isolate failures and leaks when they occur. As an example [1]: def test_create_tuple(self): variant = GLib.Variant('()', ()) self.assertEqual(variant.get_type_string(), '()') self.assertEqual(variant.n_children(), 0) variant = GLib.Variant('(i)', (3,)) self.assertEqual(variant.get_type_string(), '(i)') self.assertTrue(isinstance(variant, GLib.Variant)) self.assertEqual(variant.n_children(), 1) self.assertTrue(isinstance(variant.get_child_value(0), GLib.Variant)) self.assertEqual(variant.get_child_value(0).get_int32(), 3) ... This should be broken into multiple test functions: def test_create_tuple_empty(self): variant = GLib.Variant('()', ()) self.assertEqual(variant.get_type_string(), '()') self.assertEqual(variant.n_children(), 0) def test_create_tuple_with_int32(self): variant = GLib.Variant('(i)', (3,)) self.assertEqual(variant.get_type_string(), '(i)') self.assertTrue(isinstance(variant, GLib.Variant)) self.assertEqual(variant.n_children(), 1) self.assertTrue(isinstance(variant.get_child_value(0), GLib.Variant)) self.assertEqual(variant.get_child_value(0).get_int32(), 3) This is somewhat systemic, so the whole tests suite should be audited. [1] https://git.gnome.org/browse/pygobject/tree/tests/test_overrides_glib.py?id=3.13.90#n39
The following fix has been pushed: d1bae18 tests: Split test_strv() into multiple tests
Created attachment 285966 [details] [review] tests: Split test_strv() into multiple tests
The following fix has been pushed: 6674701 tests: Split array tests up
Created attachment 285974 [details] [review] tests: Split array tests up Split test_everything.TestEverything.test_array(), test_array_fixed_size(), and test_ptrarray() into functions of a finer granularity. This allows for easier diagnosis of problems and leaks when they occur.
The following fix has been pushed: a2f98a9 Split test_everything.TestEverything.test_string() into multiple tests
Created attachment 285976 [details] [review] Split test_everything.TestEverything.test_string() into multiple tests
-- GitLab Migration Automatic Message -- This bug has been migrated to GNOME's GitLab instance and has been closed from further activity. You can subscribe and participate further through the new bug through this link to our GitLab instance: https://gitlab.gnome.org/GNOME/pygobject/issues/80.