lundi 18 décembre 2017

How to write test case for below code in Django, python?

I need to write test cases for python scripts being developed for a web application. The framework is Django framework.

I followed many websites, and did research about how to write test cases. But thing is that, if suppose I need to write a test case for a particular feature, example: not entire module- particular lines of codes in a module, how do I need to test that code? I am confused about this thing. THere are many tools, and many ways of writing tests, but I am confused where I need to start.

Could you suggest me the best way of learning and implementing tests. For an example, one my task for writing tests is written below:

Sorted rating filter

    for category in search_results:
        for r in category:
            name_id = r["name_id"]
            obj = get_element(name_id)
            rating_sorting = get_review_average(obj)
            r['rating_sorting'] = rating_sorting
    return render(request, 'XXXapp/search.html', {'result': search_results, 'type': search_type, })

The backend code is written for sorting a particular feature. Now I need to write test case for this.

Aucun commentaire:

Enregistrer un commentaire