Skip to content

Instantly share code, notes, and snippets.

@utkarshmani1997
Last active August 10, 2017 08:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save utkarshmani1997/a29213abeb919e49c3ba49b29d2ee4c2 to your computer and use it in GitHub Desktop.
Save utkarshmani1997/a29213abeb919e49c3ba49b29d2ee4c2 to your computer and use it in GitHub Desktop.
Demo of unit testing
package main_test
import (
. "github.com/testing-demo"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)
var _ = Describe("Sum", func() {
var (
p, q, m, n, sum1, sum2 int
)
BeforeEach(func() {
p, q, sum1 = 5, 6, 11
// Putting wrong value of sum2 intentionally
m, n, sum2 = 8, 7, 16
})
Context("Addition of two digits", func() {
It("should return sum of the two digits", func() {
addition_of_two_digits := Sum(p, q)
Expect(addition_of_two_digits).Should(Equal(sum1))
})
It("should not return the sum provided", func(){
addition_of_two_digits := Sum(m, n)
Expect(addition_of_two_digits).ShouldNot(Equal(sum2))
})
})
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment