-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
Testability Strategy #63
Comments
👍 for go-gitea/proposals |
And what do you want to propose? :D |
I think this is a big topic, so we should break it in small parts. Unit testsFirst of all we should have more unit tests. These tests should be memory only (e.g.: they shouldn't touch the database, git, and if possible even the filesystem). They are tests for isolated parts of the codebase. Integration testingThis is harder, here we have to simulate HTTP requests and check if the behavior is correct. I think there are two main difficulties: How to deal with a database
I prefer to use a real database, since mocking will not catch problems like wrong SQL sintax, constraints violations, etc. #86 is a example that uses this approach. We can use a memory database for performance. How to deal with Git
In this case I prefer mocking since it will be easier than the alternative. After we have a consensus it should be write in a formal document. |
+1 for real database, and ideally against all the supported and available databases systems Should this go under go-gitea/proposals, btw ? |
Just want to add that I like to be mostly stdlib for unit tests. val, err := somefunc()
if err != nil {
t.Error(err)
}
if val != "foobar" {
t.Error("val is not foobar")
} would become: val, err := somefunc()
assert.Nil(t, err)
assert.Equals(t, "foobar", val) That's it. |
@metalmatze I agree. Go Convey was the convention on Gogs, but I also prefer testify/assert. That's another thing we should decide. |
Convey is awful. |
@makhov Even better! 😄 👍 |
Unit Tests first, that's great idea. And let's send more unit tests PRs. @makhov, do you have time on code review PRs? If you like, I want to invite you to maintainers team. |
@lunny right after somebody explain me what happens :) |
@makhov Welcome back! I have moved you from Advisor Team to Maintainers Team. |
Isn't pure golang testing an equally good approach to unit testing? The Ofc. they both comes with some different pros and cons, but the most important thing (as @lynny states) is to agree on "one" way to do it, and to actually write the tests! :) |
We use |
testify/assert works for me (never used), but have no objection if anyone wants to provide bare |
So let's use github.com/stretchr/testify, and anything else needed for unit tests? |
What about goblin? I really like this lib, especially with my BDD background on ruby from the past ;) |
I think something like Goblin could be pretty good for integration tests. But for simple Unit Tests I'd prefer something very basic like stdlib with testify. |
I disagree, unit-tests are optimal for testing db/git/fs, since they test a specific thing and not End-To-End (Integration tests) they would run fairly fast, and only once per code-path (which is almost impossible with e2e-tests) 🙂 |
@bkcsoft OK, I agree, I think it's OK to touch Git or the DB with you are actually testing things that touch them. |
I remember one PR has moved goconvey already? |
@lunny As previously mentioned, unit-tests will still use |
I vote to use only testify/assert. |
^ |
We could close this one ? |
I think yes. |
Reference #2293
Basically, we need more tests 😄
Should this go in
go-gitea/proposals
instead?Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.
The text was updated successfully, but these errors were encountered: