Hi Alex.

Big topic!

The quick points I can make here are:

* The “TestClient” based testing basically test the whole stack. They’re great 
but a bit broad brush.
* If you have a model method (say) that you want to test, create a unit test 
which just creates the model instance and executes the particular method. 
(Rather than using the test client to run the whole view stack that you wrapped 
around that.) Same with serialisers, and even views to some extent. 
(Instantiate the view, call the methods, check the return value — many times 
this doesn’t need the whole HTTP request-response cycle.)
* Some tests are better than no tests. It doesn’t have to be perfect. If you 
find a bug try to create a test for it before you fix it. These add up over 
time.

Don’t think I can say much more here.

Good luck.

Kind Regards,

Carlton


> On 21 Aug 2018, at 02:23, Alexander Lamas <[email protected] 
> <mailto:[email protected]>> wrote:
> 
> Hi Carlton,
> 
> I'm running my tests via Microsoft Visual Studio.
> 
> Maybe that's why I've got that problem.
> 
> By the way, maybe this is a subject for another thread, but, in regards to my 
> unit test, is there a better way way of testing my model class?
> I'm finishing testing the CRUD operations though.
> 
> Would you have any sample for model class unit testing, using Django Rest 
> Framework?
> 
> Also, how about my views and serializers, should I test them too? If so, how 
> can I do that?
> 
> Thank you very much!
> 
> Alex
> 
> On Mon, Aug 20, 2018 at 5:17 PM, Carlton Gibson <[email protected] 
> <mailto:[email protected]>> wrote:
> How are you running your tests? (django-admin test does all this for you…)
> 
> 
>> On 20 Aug 2018, at 10:16, Alexander Lamas <[email protected] 
>> <mailto:[email protected]>> wrote:
>> 
>> I actually, just found out that I have to add these 2 lines in the beginning 
>> of my test file.
>> 
>> import django
>> django.setup()
>> 
>> then everything works as expected.
> 
> 
> --
> You received this message because you are subscribed to the Google Groups 
> "Django REST framework" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to [email protected] 
> <mailto:[email protected]>.
> For more options, visit https://groups.google.com/d/optout 
> <https://groups.google.com/d/optout>.
> 
> 
> --
> You received this message because you are subscribed to the Google Groups 
> "Django REST framework" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to [email protected] 
> <mailto:[email protected]>.
> For more options, visit https://groups.google.com/d/optout 
> <https://groups.google.com/d/optout>.

-- 
You received this message because you are subscribed to the Google Groups 
"Django REST framework" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Attachment: signature.asc
Description: Message signed with OpenPGP

Reply via email to