Unit testing conventions #168
Replies: 7 comments 2 replies
-
my 2 cents:
|
Beta Was this translation helpful? Give feedback.
-
|
Beta Was this translation helpful? Give feedback.
-
Also not a fan of Ginkgo. Would not set a hard rule requiring or prohibiting table tests. Sometimes it makes sense; sometimes it doesn't. Would recommend using testify for simple assertions to save some typing. Would recommend against too many shared helper functions that set up CRs and whatnot - it's easy to forget/be unaware of what they do exactly... |
Beta Was this translation helpful? Give feedback.
-
ok - I'm going to close this discussion. I'm opening a ticket for us to document our unit testing guidelines. I believe what Andy has up here is a good place to start. I'll also create some ticket for refactoring the current unit tests from ginkgo to go test. |
Beta Was this translation helpful? Give feedback.
-
I agree that keeping one standard is better than having multiple styles (+1). I’d like to just clarify a point that may be misunderstood:
This is not true. A However, you can structure your suite within the same file as the tests, similar to standard Go testing, if you prefer. The Examplepackage mypackage_test
import (
"testing"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
)
func TestMyCode(t *testing.T) {
RegisterFailHandler(Fail)
RunSpecs(t, "MyCode Suite")
}
var _ = Describe("MyCode", func() {
It("should perform action A", func() {
Expect(true).To(BeTrue())
})
It("should perform action B", func() {
Expect(true).To(BeTrue())
})
}) |
Beta Was this translation helpful? Give feedback.
-
Summary of the Cons Raised Here and Discussed via Slack with My CommentsCons of Using Ginkgo (Based on Discussions with My comments/thoughts)
Pros of Using Ginkgo
IHMO: I would stick with Gingko for E2E tests (at least) because
These are why I would prefer to keep everything aligned with the Kubernetes/OCP ecosystem. I’ve tried to address all the arguments raised against using Ginkgo and outlined the cons where applicable with my comments. |
Beta Was this translation helpful? Give feedback.
-
We have very little ginkgo in our current v1 items. operator-controller looks like it has it due to registry using it. catalogd has a bit more and I went and looked at what we're doing with it there. I have to say those tests are fine, but they're opaque to my IDE that can do such a nice job running and debugging gotest tests. Want to run just one test and hit a breakpoint to help reason about a complex failure? Works with gotest tests, but you get no help with the gingko ones. IMO gingko kind of slipped into our project and we should really standardize on not using it. |
Beta Was this translation helpful? Give feedback.
-
A recent discussion in #142 raised a couple of questions around what our unit testing conventions ought to be:
For the sake of consistency, I'm putting this out there to our community so we can establish some best practices and conventions. IMHO:
Beta Was this translation helpful? Give feedback.
All reactions