unit testing - Execute test cases in a pre-defined order -


is there way execute test cases in golang in pre-defined order.

p.s: writing test cases life cycle of event. have different api's curd operations. want run these test cases in particular order if event created can destroyed.

also can value 1 test case , pass input another. (example:- test delete event api, need event_id when call create_event test case)

i new golang, can please guide me through.

thanks in advance

the way encapsulate tests 1 test function, calls sub-functions in right order , right context, , pass testing.t pointer each can fail. down-side appear 1 test. in fact case - tests stateless far testing framework concerned, , each function separate test case.

note although tests may run in order written in, found no documentation stating contract of sort. though can write them in order , keep state external global variables - that's not recommended.

the flexibility framework gives since go 1.4 testmain method lets run before/after steps, or setup/teardown:

func testmain(m *testing.m) {      if err := setup(); err != nil {         panic(err)     }     rc := m.run()     teardown()     os.exit(rc) } 

but won't give want. way safely like:

// whole stateful sequence of tests - testing framework it's 1 case func testwrapper(t *testing.t) {     // let's pass context containing struct    ctx := new(context)    test1(t, ctx)    test2(t, ctx)    ... }  // holds context between methods type context struct {        eventid string }  func test1(t *testing.t, c *context) {    // thing, , can manipulate context    c.eventid = "something" }   func test2(t *testing.t, c *context) {    // thing, , can manipulate context    dosomethingwith(c.eventid) }  

Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -