smarty / assertions

Fluent assertion-style functions used by goconvey and gunit. Can also be used in any test or application.
Other
100 stars 34 forks source link

Is there an assertion like So(..) that skips the whole tests without reporting an error if the assertion fails? #23

Closed dmigwi closed 7 years ago

dmigwi commented 7 years ago

I have a method m2 that depend that depends on the output of method m1.

I would like to exit the m1 tests QUIETLY, if m1 assertions fails before m2 tests assertions start executing.

Currently, So(...) reports the m1 assertions failure whereas the main focus should be on the output of m2 assertions if all m1 assertions passed.

If any of the m1 assertions failed, the test should exit quietly skipping all other assertions. Do we have a function that I can use to run m1 assertions while I use So(...) to run m2 assertions?

mdwhatcott commented 7 years ago

Hmm, I might need to see some sample code to fully understand what you're asking for. Did you know that So returns a bool indicating success or failure of an assertion?

dmigwi commented 7 years ago

Here is a sample code.

func TestMakeDelivery(t *testing.T){

     var fetchInfo = func (location string) {
            address, err := getAddress() // m1 function
            So(address, ShouldNotBeEmpty)      // m1 assertions
            So(err, ShouldBeNil)

            info, err := getInfor(address)  // m2 function
         }

     Convey("Values of the infor should contain the correct information", t , func (){
         fetchInfo("kenya") 

          // m2 assertions
         So(info.Success, ShouldBeTrue)
         So(info.Address, ShouldNoBeEmpty)
     }
    .... // more tests
}

fetchInfo is being used by several other tests. I would like to have a situation whereby when the m1 assertion fails the whole test is skipped rather than returning an error showing that the whole tests failed. m1 functions is like a helper function such that its failure should not indicate the failure of the whole test but a message can be displayed for the developer that only the helper function failed but not the whole test..

mdwhatcott commented 7 years ago

The assertions package wasn't designed to allow that kind of decision making in your tests by itself. I would just use if statements to check relevant state in m1 and decide whether it passes. m1 could set a bool that is consulted before attempting the m2 assertions.

dmigwi commented 7 years ago

The fact that So(...) returns a boolean and a string, is one step closer to what I wanted to achieve.

func So(actual interface{}, assert assertion, expected ...interface{}) (bool, string)

Let me try customize it and see if it will fit my specific use case..