Hey,Thanks for both the explanations. They really make sense to me.I referred to the following link and thought assertions are against go best practices => https://golang.org/doc/faq#testing_framework.
--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/c96d148e-6b73-40d0-9e3c-b8666b2e9d6dn%40googlegroups.com.
For unit tests, we need to mock the dependent interfaces either by creating our own mock implementation of the interface or by using third party packages like testify/mocks.
On Oct 5, 2020, at 8:14 AM, 'Bryan C. Mills' via golang-nuts <golan...@googlegroups.com> wrote:
As for mocking dependencies: in my experience, the best strategy is often not to.
--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/2b1affd7-1599-4943-8419-d9718f17780fn%40googlegroups.com.
--
You received this message because you are subscribed to a topic in the Google Groups "golang-nuts" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/golang-nuts/ZoJ5isoeea4/unsubscribe.
To unsubscribe from this group and all its topics, send an email to golang-nuts...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/CAOyqgcXNV6bLQQUFmVn14xnxheALTKbv1_oQODovboLEziPKSw%40mail.gmail.com.
> Or, it will be written as assert.Equal(got, want, fmt.Sprintf("MyFunction(%v)", input)), but that is harder to write, and therefore less likely to be written.That obviously depends on the implementation details but since we talk about testify the API is: assert.Equal(t, want, got, format, [args...]).
--On Mon, 5 Oct 2020 at 18:45, Ian Lance Taylor <ia...@golang.org> wrote:On Mon, Oct 5, 2020 at 8:47 AM Viktor Kojouharov <vkojo...@gmail.com> wrote:
>
> I don't find any difference between calling t.Errorf and assert.Something with a provided message. Both will populate the test log, with the later giving you more details exactly where things differ from the expectation.
The difference is that since people write t.Error while writing the
test, it's very easy to provide all the relevant information, which in
many cases will involve more than just the values being compared. A
common example would be a message like "MyFunction(%v) = %v, want %v".
When using an assert style function, the message will tend to lose the
value passed to MyFunction. Or, it will be written as
assert.Equal(got, want, fmt.Sprintf("MyFunction(%v)", input)), but
that is harder to write, and therefore less likely to be written.
(It's also less efficient in the common case, though for a test that
is unlikely to matter.)
Ian
--
You received this message because you are subscribed to a topic in the Google Groups "golang-nuts" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/golang-nuts/ZoJ5isoeea4/unsubscribe.
To unsubscribe from this group and all its topics, send an email to golang-nuts...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/CAOyqgcXNV6bLQQUFmVn14xnxheALTKbv1_oQODovboLEziPKSw%40mail.gmail.com.
--Vladimir Varankin
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/CAGLqCMmj7NB3Sem0BDdyJBj-cxGXVmBY-6StRXAP6MvwZUyOnQ%40mail.gmail.com.
The core of the problem is that `assert` functions generally cannot provide enough context to produce useful test failures. An `assert` call compares values, but does not report the relevant inputs and calls leading to those values — and the description of the inputs and the operations performed on those inputs are what the person diagnosing the test failure will need in order to figure out what went wrong.