-
-
Notifications
You must be signed in to change notification settings - Fork 667
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
BeforeAll/AfterAll? #70
Comments
hey @modocache, The lack of
Because Does this make sense? I'd love to hear your thoughts. FWIW I've avoided RSpec's |
That makes a lot of sense, thanks for the explanation! I came across my specific use case when writing this. The post describes testing a HTTP handler. I believe creating the handler is fairly expensive, especially considering it opens a connection to a database, so I was hoping to only do it once. But I need a reference to the handler, so I can't easily move the initialization into a That being said, I've only just started looking into web development with Go, so I'm certain there's a better way to accomplish what I'm doing. I was mainly curious as to why you'd leave out |
I know you got your answer, but just to add a little: Always try it before If you must share a handle, you really should be able to initialize it in I'll note that sometimes I'm torn about how many expectations to to put Good luck! |
Glad that was helpful @modocache -- and thanks for the sweet blog posts mentioning Ginkgo! Also, thanks for chiming in @rnapier - I agree with your points. I also prefer smaller |
I know this is an ancient issue, but I'll mention another way this is an issue. In kubernetes, we have a rather large end-to-end test suite. There is a single suite for the entire project, and so the nested Describe/Context blocks often have very specific needs. As this is an e2e setup, it's often the case that we need to create certain API objects and wait for them to stabilize in the running server. This is a high-latency operation. Currently we do this in BeforeEach blocks, which works but it strongly encourages test writers to build gigantic It() blocks because of the state teardown/construction. In effect, we have the same amount of test assertions "sharing state" as we would with BeforeAll, but the tests are large, harder to read, and they fail with very little granularity. BeforeAll/AfterAll or equivalently nested suites would be a useful abstraction for this case. |
I need BeforeAll/AfterAll too. I created integration test for my application. It prepares environment, starts app and performs tests. So I'd like to test my app with different config files and different environment variables. And I have more then one test per each configuration. |
@and-hom can you point me at a concrete or specific example? PSA: If you want This will not work with paralellized tests or |
I think this would be a nice addition. It helps discourage massive func BeforeAll(fn func()) {
first := true
Before(func() {
if first {
fn()
first = false
}
})
} Which works well with our parallelized (and randomized) test setup. This has been a boon in dealing with some particularly unreliable testing infrastructure (rapid iteration of |
I can see how this makes I really need an I've been racking my brain trying to come up with various workarounds, but since the |
Hi, I also would like to see |
+1 |
* Pure golang * Framework that allows remote execution of commands and other operations on DinD k8s node (i.e. what `docker exec` does), k8s pods (like `kubectl exec`) and created VMs (like vmssh.sh) without executing external apps * ginkgo test framework drop-in replacement that extends the framework with ability to have BeforeAll/AfterAll methods that do setup/teardown for current context as a workaround for onsi/ginkgo#70 * e2e suite is compiled into a standalone binary that has no system dependencies and can be run from outside of the cluster with virtlet deployed * tests are performed in a temporary namespace that is deleted afterwards Left to implement * Further extend framework functionality * Migrate rest of e2e tests from e2e.sh to new framework * Completely delete e2e.sh (now both old and new e2e's are executed) * Add CLI flag to skip tests that depend on DinD (i.e. that uses `docker exec` functionality to do something on the nodes) so that it would be possible to execute e2e against remote/bare-metal/etc k8s cluster Also, noticeably decrease project build time for subsequent builds by adding `-i` flag to `go build`
* Pure golang * Framework that allows remote execution of commands and other operations on DinD k8s node (i.e. what `docker exec` does), k8s pods (like `kubectl exec`) and created VMs (like vmssh.sh) without executing external apps * ginkgo test framework drop-in replacement that extends the framework with ability to have BeforeAll/AfterAll methods that do setup/teardown for current context as a workaround for onsi/ginkgo#70 * e2e suite is compiled into a standalone binary that has no system dependencies and can be run from outside of the cluster with virtlet deployed * tests are performed in a temporary namespace that is deleted afterwards Left to implement * Further extend framework functionality * Migrate rest of e2e tests from e2e.sh to new framework * Completely delete e2e.sh (now both old and new e2e's are executed) * Add CLI flag to skip tests that depend on DinD (i.e. that uses `docker exec` functionality to do something on the nodes) so that it would be possible to execute e2e against remote/bare-metal/etc k8s cluster Also, noticeably decrease project build time for subsequent builds by adding `-i` flag to `go build`
* Pure golang * Framework that allows remote execution of commands and other operations on DinD k8s node (i.e. what `docker exec` does), k8s pods (like `kubectl exec`) and created VMs (like vmssh.sh) without executing external apps * ginkgo test framework drop-in replacement that extends the framework with ability to have BeforeAll/AfterAll methods that do setup/teardown for current context as a workaround for onsi/ginkgo#70 * e2e suite is compiled into a standalone binary that has no system dependencies and can be run from outside of the cluster with virtlet deployed * tests are performed in a temporary namespace that is deleted afterwards Left to implement * Further extend framework functionality * Migrate rest of e2e tests from e2e.sh to new framework * Completely delete e2e.sh (now both old and new e2e's are executed) * Add CLI flag to skip tests that depend on DinD (i.e. that uses `docker exec` functionality to do something on the nodes) so that it would be possible to execute e2e against remote/bare-metal/etc k8s cluster Also, noticeably decrease project build time for subsequent builds by adding `-i` flag to `go build`
* Pure golang * Framework that allows remote execution of commands and other operations on DinD k8s node (i.e. what `docker exec` does), k8s pods (like `kubectl exec`) and created VMs (like vmssh.sh) without executing external apps * ginkgo test framework drop-in replacement that extends the framework with ability to have BeforeAll/AfterAll methods that do setup/teardown for current context as a workaround for onsi/ginkgo#70 * e2e suite is compiled into a standalone binary that has no system dependencies and can be run from outside of the cluster with virtlet deployed * tests are performed in a temporary namespace that is deleted afterwards Left to implement * Further extend framework functionality * Migrate rest of e2e tests from e2e.sh to new framework * Completely delete e2e.sh (now both old and new e2e's are executed) * Add CLI flag to skip tests that depend on DinD (i.e. that uses `docker exec` functionality to do something on the nodes) so that it would be possible to execute e2e against remote/bare-metal/etc k8s cluster Also, noticeably decrease project build time for subsequent builds by adding `-i` flag to `go build`
* Pure golang * Framework that allows remote execution of commands and other operations on DinD k8s node (i.e. what `docker exec` does), k8s pods (like `kubectl exec`) and created VMs (like vmssh.sh) without executing external apps * ginkgo test framework drop-in replacement that extends the framework with ability to have BeforeAll/AfterAll methods that do setup/teardown for current context as a workaround for onsi/ginkgo#70 * e2e suite is compiled into a standalone binary that has no system dependencies and can be run from outside of the cluster with virtlet deployed * tests are performed in a temporary namespace that is deleted afterwards Also, noticeably decrease project build time for subsequent builds by adding `-i` flag to `go build`
* Pure golang * Framework that allows remote execution of commands and other operations on DinD k8s node (i.e. what `docker exec` does), k8s pods (like `kubectl exec`) and created VMs (like vmssh.sh) without executing external apps * ginkgo test framework drop-in replacement that extends the framework with ability to have BeforeAll/AfterAll methods that do setup/teardown for current context as a workaround for onsi/ginkgo#70 * e2e suite is compiled into a standalone binary that has no system dependencies and can be run from outside of the cluster with virtlet deployed * tests are performed in a temporary namespace that is deleted afterwards Also, noticeably decrease project build time for subsequent builds by adding `-i` flag to `go build`
* Pure golang * Framework that allows remote execution of commands and other operations on DinD k8s node (i.e. what `docker exec` does), k8s pods (like `kubectl exec`) and created VMs (like vmssh.sh) without executing external apps * ginkgo test framework drop-in replacement that extends the framework with ability to have BeforeAll/AfterAll methods that do setup/teardown for current context as a workaround for onsi/ginkgo#70 * e2e suite is compiled into a standalone binary that has no system dependencies and can be run from outside of the cluster with virtlet deployed * tests are performed in a temporary namespace that is deleted afterwards Also, noticeably decrease project build time for subsequent builds by adding `-i` flag to `go build`
* Pure golang * Framework that allows remote execution of commands and other operations on DinD k8s node (i.e. what `docker exec` does), k8s pods (like `kubectl exec`) and created VMs (like vmssh.sh) without executing external apps * ginkgo test framework drop-in replacement that extends the framework with ability to have BeforeAll/AfterAll methods that do setup/teardown for current context as a workaround for onsi/ginkgo#70 * e2e suite is compiled into a standalone binary that has no system dependencies and can be run from outside of the cluster with virtlet deployed * tests are performed in a temporary namespace that is deleted afterwards Also, noticeably decrease project build time for subsequent builds by adding `-i` flag to `go build`
* Pure golang * Framework that allows remote execution of commands and other operations on DinD k8s node (i.e. what `docker exec` does), k8s pods (like `kubectl exec`) and created VMs (like vmssh.sh) without executing external apps * ginkgo test framework drop-in replacement that extends the framework with ability to have BeforeAll/AfterAll methods that do setup/teardown for current context as a workaround for onsi/ginkgo#70 * e2e suite is compiled into a standalone binary that has no system dependencies and can be run from outside of the cluster with virtlet deployed * tests are performed in a temporary namespace that is deleted afterwards Also, noticeably decrease project build time for subsequent builds by adding `-i` flag to `go build`
* Pure golang * Framework that allows remote execution of commands and other operations on DinD k8s node (i.e. what `docker exec` does), k8s pods (like `kubectl exec`) and created VMs (like vmssh.sh) without executing external apps * ginkgo test framework drop-in replacement that extends the framework with ability to have BeforeAll/AfterAll methods that do setup/teardown for current context as a workaround for onsi/ginkgo#70 * e2e suite is compiled into a standalone binary that has no system dependencies and can be run from outside of the cluster with virtlet deployed * tests are performed in a temporary namespace that is deleted afterwards Also, noticeably decrease project build time for subsequent builds by adding `-i` flag to `go build`
* Pure golang * Framework that allows remote execution of commands and other operations on DinD k8s node (i.e. what `docker exec` does), k8s pods (like `kubectl exec`) and created VMs (like vmssh.sh) without executing external apps * ginkgo test framework drop-in replacement that extends the framework with ability to have BeforeAll/AfterAll methods that do setup/teardown for current context as a workaround for onsi/ginkgo#70 * e2e suite is compiled into a standalone binary that has no system dependencies and can be run from outside of the cluster with virtlet deployed * tests are performed in a temporary namespace that is deleted afterwards Also, noticeably decrease project build time for subsequent builds by adding `-i` flag to `go build`
I'm facing the same issue: working with openshift (kubernetes based) I have a test suite devided to several contexts and specs. Some tests needs a setup before their execution. The setup takes a long time, but it's the same setup for all |
@tzvatot Thanks for your feedback! Is this code somewhere I can see? |
Unfortunately no. But we might open it up sometime in the future. |
+1 on the |
Doesn't
|
@arxeiss no, it does not solve the problem. As mentioned in the documentation, the BeforeSuite and AfterSuite are global. For example, assume I have a single test suite called "regression". This test suite contains several test cases. Few of the tests share the same exact setup, which is costly both in time and resources. So instead of forcing each of those tests to do it's own setup, we like to run that setup once, to create some basic resources that will be used by all those tests, and once they finish, we can remove those resources. Of course, you may argue that those should be in a separated Suite, but since we have several such "groups" of tests that should share the setup and teardown in the "regression" suite, it means that every real life suite will actually be a group of suites (which opens another question about missing BeforeEachSuite and AfterEachSuite). |
Generally, it does make sense without BeforeAll and AfterAll. -> Therefore, +1 for BeforeAll / AfterAll. Also would like to know the best practices for integration tests using Ginkgo. |
Ginkgo 2.0 (see #711) will hopefully add some additional controls to help with this. |
Am happy to share that over 7 years later, the ver2 branch now includes support for |
We do use Ginkgo to develop a framework to test applications of Openshift/Kubernetes and having BeforeAll is really sweet option. Otherwise, we're forced to do that ourselves (not in a clean way) |
@onsi how can I find the PR for this? what version will include it? |
hey - this shipped in 2.0 and is documented here. |
@onsi it seems that the BeforeAll/AfterAll is strongly tight with Ordered context. This cause the following issue: |
hey @tzvatot do you mind opening a new issue so we can discuss it there? i'd like to learn more about what you're doing in the table test to figure out what potential solutions for you are. |
cross-posting here since this is the issue that folks thinking about 2.7.0 introduces the |
RSpec includes
before(:all)
andafter(:all)
nodes. These nodes are executed once at the beginning or end of an example group, respectively:When run,
rspec
outputs:I was surprised that Ginkgo does not include
BeforeAll
orAfterAll
functions. Is this a conscious omission? Would you consider a pull request which adds these functions?The text was updated successfully, but these errors were encountered: