Skip to content

Commit c2b97a5

Browse files
committed
#244 minor - work in progress
1 parent 731a74c commit c2b97a5

File tree

1 file changed

+59
-0
lines changed

1 file changed

+59
-0
lines changed

docs/test-strategy/testing-strategy.md

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,69 @@ Similarly for OS X. With Windows this is not entirely the same, and different wi
4848

4949
None of the above tests should ever be necessary at the higher levels of testing. Furthermore, testing things that are not happy path may be worthwhile here, depending on where bugs showed up in the past, and future.
5050

51+
An exellent example of this can be found in [gh_test.go](https://github.com/Praqma/git-phlow/blob/master/plugins/gh_test.go) :
52+
```
53+
func TestAuthorize(t *testing.T) {
54+
Convey("Running tests on 'Authorize' request", t, func() {
55+
Convey("Authorize should return token", func() {
56+
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
57+
if r.Method != "POST" {
58+
t.Errorf("Expected Request 'POST', got '%s'", r.Method)
59+
}
60+
if r.URL.EscapedPath() != "/authorizations" {
61+
t.Errorf("Expected request to 'repos', got '%s'", r.URL.EscapedPath())
62+
}
63+
w.WriteHeader(http.StatusCreated)
64+
w.Write([]byte(authResponse))
65+
66+
}))
67+
68+
defer ts.Close()
69+
GitHub.Auth.URL = ts.URL + "/authorizations"
70+
token, err := GitHub.Auth.Auth("simon", "password")
71+
t.Log(err)
72+
So(token, ShouldEqual, "abcdefgh12345678")
73+
So(err, ShouldBeNil)
74+
})
75+
})
76+
}
77+
```
78+
79+
As well as [branch_test.go](https://github.com/Praqma/git-phlow/blob/master/githandler/branch_test.go)
80+
81+
```
82+
func TestBranch(t *testing.T) {
83+
Convey("Running tests on 'Branch' function", t, func() {
84+
85+
testfixture.CreateTestRepository(t, false)
86+
87+
Convey("branch should return List of branches", func() {
88+
info, err := Branch()
89+
So(len(info.List), ShouldEqual, 11)
90+
So(err, ShouldBeNil)
91+
})
92+
93+
Convey("branch should return Current branch", func() {
94+
info, err := Branch()
95+
So(info.Current, ShouldEqual, "master")
96+
So(err, ShouldBeNil)
97+
})
98+
99+
testfixture.RemoveTestRepository(t)
100+
101+
})
102+
}
103+
```
104+
These are marked as integration tests since neither of them execute on a singular method, but need to authenticate against github (network call) and create a repository to execute on (system call) respectively.
105+
106+
51107
## Methods (Unit test level)
52108
Every method should have a unit test, as it's a straight forward project to run TDD on. However as with most prototypes this is probably not the case, and thus it is necessary to determine which parts of the system are still exploratory.
53109
Writing a lot of unit tests for existing methods, which are still being restructured is a waste of productivity.
54110

111+
Good examples of unit tests would be this method in []()
112+
113+
55114
## Handling "legacy" code
56115
Legacy code for Git Phlow is from here defined as :
57116

0 commit comments

Comments
 (0)