Home > Mobile >  Is there a way to ignore test errors coming from third party packages during unit tests?
Is there a way to ignore test errors coming from third party packages during unit tests?

Time:02-18

My tests are failing due to a 3rd party error that is irrelevant to the tests themselves. Basically some testserver I have to use fails to shutdown on Windows OS but actually runs fine.

I need to ignore the errors it generates, but they are in the defer part as below. Is there a way to completely ignore any errors coming from the first two lines?

func TestDoSomething(t *testing.T) {
    testServer := setupTestNomad(t) //contains 3rd party test server creation
    defer testServer.Stop()  //actually fails here in the 3rd party struct due to 3rd party code itself

    data := DoSomething()
    if data == nil { //data is not null and all is fine here
        t.Errorf("Failed, data null")
    }
}

Test dies because of this within their code

enter image description here

CodePudding user response:

Is there a way to ignore test errors coming from third party packages during unit tests?

No, not in your case because the test is not "from third party package": The test is yours and it fails. The fact that your code calls a function from a "third party package" has no meaning here.

CodePudding user response:

Moving it to another namespace didn't help nor did the above helpful comments.

The testing.T struct I carry around and use to create a new Nomad Test server allows the 3rd party code to fail my test. Not using that and using a new object as below solves this problem.

nomadTestUtil.NewTestServer(&testing.T{},...
  • Related