Replies: 1 comment
-
For the proof of concept check PR: #535 |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Problems
We have a good test coverage (above 80%). This helps to lower mistakes during development and improves code quality. But, there are some problems with our current testing method:
Random Test Failures
Sometimes, our tests fail randomly. This often happens with GitHub Actions. For example, here and here. For some failures, we can guess the reason. For example, in the second case, the random number was probably zero.
However, we need to be able to reproduce these failed tests. We cannot ignore these occasional failures.
Test Functions inside the code
We have some Test functions in the Code, like:
GenerateTestAccount
. These functions help us make random objects in tests. But, they are part of the main code. We need to separate these functions from the main code. We should be careful about import cycles error in Golang.Global Test Variables
In some modules, we use global variables for testing. These usually start with
t
, liketState
. But, in general, global variables are not recommended.Solution
A
TestSuite
can make our tests better. We can create a pseudo-random source and log it. If a test fails, we can use the same source to reproduce the failed test. We can also move all Test functions into theTestSuite
.For testing global variables, we can create a struct and put a
TestSuite
instance there.We should also do more property tests. And we should use table driven tests when possible.
Beta Was this translation helpful? Give feedback.
All reactions