Re: [Vala] Using TestCase class: assert (this is Object) fails in method, but not in constructor



You may also find the Gee.TestCase class suits your needs - it certainly
makes the tests easier to read and is more xUnit like in its approach than
the 'naked' GLib Test classes.

https://esite.ch/2012/06/writing-tests-for-vala/

Gives a good overview - and if I recall the GXml tests that Daniel
mentioned uses it as well.

Cheers
Chris D

2016-02-04 14:09 GMT-08:00 Daniel Espinosa <esodan gmail com>:

GXml have a test suite may you want to check. I has more than 50 tests
cases.
El feb. 4, 2016 3:04 PM, "Al Thomas" <astavale yahoo co uk> escribió:



----- Original Message -----
From: Felipe Lavratti <felipelav gmail com>
Sent: Thursday, 4 February 2016, 20:18
Subject: [Vala] Using TestCase class: assert (this is Object) fails in
method, but not in constructor

Have a look at this code:

    public class Tests : Object {

        public Tests () {
            assert (this is Object); // THIS ASSERTION PASSES
            ts = new TestSuite ("dot_cap_dimmer") ;
            ts.add (new TestCase ("construction", (TestFixtureFunc)
setup, (TestFixtureFunc) test_construction, (TestFixtureFunc)
teardown)) ;
            TestSuite.get_root ().add_suite (ts) ;
        }

        void setup(void * fixture) {
            assert (this is Object);  // THIS ASSERTION FAILS
            this.cut = new DotCapDimmer () ;
            this.cut.on_change.connect (slot) ;
            this.called = false ;
        }
        ...
     }

Would anyone know what happens to the `this` variable when called
from the TestCase ? How came it is no longer an Object anymore ?


You need to instantiate your fixture so it has `this` to act upon.
Your fixture should be a separate object to the test.
As an outline;


void main( string[] args ) {

  Test.init(ref args);
  TestSuite suite = new TestSuite( "DotCapDimmer" );
  TestSuite.get_root ().add_suite (suite);

  MyTestFixture fixture = new MyTestFixture();
  suite.add( new TestCase ( "MyFirstTestCase", fixture.set_up,
(TestFixtureFunc)test_my_first_test, fixture.tear_down ));
  Test.run();
}

void test_my_first_test( MyTestFixture fixture ) {
    // do testing

}



I put the test in a namespace like
UnitTest.ModuleDirectory.FilenameOfClassToBeTested

There is also g_test_add_data_func_full () instead, but I haven't used
that yet.

Al
_______________________________________________
vala-list mailing list
vala-list gnome org
https://mail.gnome.org/mailman/listinfo/vala-list

_______________________________________________
vala-list mailing list
vala-list gnome org
https://mail.gnome.org/mailman/listinfo/vala-list




-- 
Chris Daley
Pacific Northwest

e: chebizarro gmail com
w: http://chrisdaley.biz
m: +1601 980 1249
s: chebizarro
tw: chebizarro
tz: PDT


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]