Skip to content
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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Testability Strategy #63

Closed
bkcsoft opened this issue Nov 4, 2016 · 25 comments
Closed

Testability Strategy #63

bkcsoft opened this issue Nov 4, 2016 · 25 comments
Labels
type/proposal The new feature has not been accepted yet but needs to be discussed first.

Comments

@bkcsoft
Copy link
Member

bkcsoft commented Nov 4, 2016

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.

@bkcsoft bkcsoft added the type/proposal The new feature has not been accepted yet but needs to be discussed first. label Nov 4, 2016
@xinity
Copy link
Contributor

xinity commented Nov 4, 2016

馃憤 for go-gitea/proposals

@tboerger
Copy link
Member

tboerger commented Nov 4, 2016

And what do you want to propose? :D

@andreynering
Copy link
Contributor

I think this is a big topic, so we should break it in small parts.

Unit tests

First 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 testing

This 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

  • Mocking the database
  • We can test against a real 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

  • We can mock the interface that talk to git
  • We can write scripts to generate repositories and use real 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.

@strk
Copy link
Member

strk commented Nov 5, 2016

+1 for real database, and ideally against all the supported and available databases systems
And also I think using real git would be better

Should this go under go-gitea/proposals, btw ?

@metalmatze
Copy link
Contributor

Just want to add that I like to be mostly stdlib for unit tests.
Nevertheless I find https://godoc.org/github.com/stretchr/testify/assert extremely useful to prevent a lot of boilerplate.

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.

@andreynering
Copy link
Contributor

@metalmatze I agree. Go Convey was the convention on Gogs, but I also prefer testify/assert. That's another thing we should decide.

@makhov
Copy link
Contributor

makhov commented Nov 5, 2016

Convey is awful.
@metalmatze, note that testify/assert has methods assert.Error and assert.NoError to test errors

@metalmatze
Copy link
Contributor

@makhov Even better! 馃槃 馃憤

@lunny
Copy link
Member

lunny commented Nov 6, 2016

Unit Tests first, that's great idea. And let's send more unit tests PRs.
About the unit test framework, we have to determine one ASAP.

@makhov, do you have time on code review PRs? If you like, I want to invite you to maintainers team.

@makhov
Copy link
Contributor

makhov commented Nov 6, 2016

@lunny right after somebody explain me what happens :)

@lunny
Copy link
Member

lunny commented Nov 6, 2016

@makhov Welcome back! I have moved you from Advisor Team to Maintainers Team.

@odinuge
Copy link
Contributor

odinuge commented Nov 6, 2016

Isn't pure golang testing an equally good approach to unit testing? The assertion approach works, but in my opinion, the normal go-one works better. Eg. it forces the user testing to handle errors, instead of just panicking.

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! :)

@makhov
Copy link
Contributor

makhov commented Nov 6, 2016

We use testing with testify/assert and it works for us.

@strk
Copy link
Member

strk commented Nov 6, 2016

testify/assert works for me (never used), but have no objection if anyone wants to provide bare testing tests too

@lunny
Copy link
Member

lunny commented Nov 7, 2016

So let's use github.com/stretchr/testify, and anything else needed for unit tests?

@tboerger
Copy link
Member

tboerger commented Nov 7, 2016

What about goblin? I really like this lib, especially with my BDD background on ruby from the past ;)

@metalmatze
Copy link
Contributor

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.

@bkcsoft
Copy link
Member Author

bkcsoft commented Nov 7, 2016

@andreynering

First 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).

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) 馃檪

@andreynering
Copy link
Contributor

@bkcsoft OK, I agree, I think it's OK to touch Git or the DB with you are actually testing things that touch them.

@tboerger tboerger added this to the 1.x.x milestone Nov 11, 2016
@lunny
Copy link
Member

lunny commented Feb 11, 2017

I remember one PR has moved goconvey already?

@bkcsoft
Copy link
Member Author

bkcsoft commented Feb 12, 2017

@lunny As previously mentioned, unit-tests will still use testify/assert while integration-tests could use goconvey (even though I don't like that lib...)

@andreynering
Copy link
Contributor

I vote to use only testify/assert.

@lunny
Copy link
Member

lunny commented Feb 12, 2017

^

@sapk
Copy link
Member

sapk commented Dec 13, 2017

We could close this one ?

@lunny
Copy link
Member

lunny commented Dec 13, 2017

I think yes.

@lunny lunny closed this as completed Dec 13, 2017
@lunny lunny removed this from the 1.x.x milestone Dec 13, 2017
@go-gitea go-gitea locked and limited conversation to collaborators Nov 23, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
type/proposal The new feature has not been accepted yet but needs to be discussed first.
Projects
None yet
Development

No branches or pull requests

10 participants