junction
junction copied to clipboard
Improve code coverage
we need to write unit tests!
+1. Slowly keep adding it, not at one shoot :-)
+1
I can write tests. Is there a specific way I have to write them? I usually put them in the application folder.
Yes, it is good to have unit_tests
directory inside the app directory
. Unit tests
shouldn't connect to db, mocks/stubs
are used with help of mock library
. Use py.test
as test runner and plain asserts.
Writing unit test is super fun when the view layer is split into multiple function where each function does one thing. While writing unit tests please feel free to add extra layer/refactor the functions.
Though the title says about unit tests, you should also write functional tests starting from view to response.
Start with something simple and we can add more as we proceed.
I am having trouble running the existing tests. py.test
fails with internal error. Is there a specific way to run tests?
Show the output ?
On Mon, Jul 6, 2015 at 3:57 PM, arjoonn sharma [email protected] wrote:
I am having trouble running the existing tests. py.test fails with internal error. Is there a specific way to run tests?
— Reply to this email directly or view it on GitHub https://github.com/pythonindia/junction/issues/219#issuecomment-118803380 .
Regards Kracekumar Ramaraju http://kracekumar.com +91 85530 29521
Aah, sorry, it was my mistake. I was mistakenly running from ~/dev/junction
as opposed to ~/dev/junction/junction
. Realized this immediately after I commented.
Is this how I should proceed? https://github.com/theSage21/junction/commit/265f053b2d9945973302bcf21a8fc1ab1801366b
You don't need to mock email functionality, checkout outbox
module[1].
With pytest, you can also use available outbox
fixture[2], while in development django is set to use consoleBackend
so not actual email sent out anyways.
Sample Test:
def test_some_function(outbox):
some_function()
assert len(outbox) == 1
assert "sometext" in outbox
Footnotes:
[1] https://docs.djangoproject.com/en/1.8/topics/testing/tools/#email-services [2] https://github.com/pythonindia/junction/blob/master/tests/fixtures.py#L49-L53
@palnabarun @pradyunsg How much code coverage should be good ? We can split up up the task per module.
@ananyo2012 We should at least cover all important functionalities.
The coverage percentage metric is misleading. Lower coverage certainly means more tests are required to be written, but higher coverage does not lead to well-tested software.