1

Ao executar os comandos de teste do Django, nenhum teste é reconhecido.

Minha estrutura de arquivos é a seguinte:

Eagle/
  eagle/
    __init__.py
    settings.py
    urls.py
    wsgi.py
  dashboard/
    __init__.py
    admin.py
    apps.py
    forms.py
    models.py
    tests.py
    urls.py
    views.py

O conteúdo de meu arquivo de testes é:

from django.urls import reverse, resolve
from django.test import TestCase
from . import views


# Create your tests here.
class UrlTest(TestCase):
    def dashboard_status_code(self):
        url = reverse('dashboard')
        response = self.client.get(url)
        self.assertEquals(response.status_code, 204)

    def dashboard_view(self):
        view = resolve('/accounts/')
        self.assertEquals(view.func, views.dashboard)

Já tentei executar os seguintes comandos para testar:

python manage.py test
python manage.py test dashboard
python manage.py test dashboard/
python manage.py test dashboard.tests

todos eles me trazem a seguinte saída:

Creating test database for alias 'default'...
System check identified no issues (0 silenced).

----------------------------------------------------------------------
Ran 0 tests in 0.000s

OK
Destroying test database for alias 'default'...

Se ajudar em algo, o código esta todo no GitHub (Aqui).

1 Resposta 1

0

O nome dos métodos que são testes, devem começar com test_

Então ficaria algo como:

from django.urls import reverse, resolve
from django.test import TestCase
from . import views


# Create your tests here.
class UrlTest(TestCase):
    def test_dashboard_status_code(self):
        url = reverse('dashboard')
        response = self.client.get(url)
        self.assertEquals(response.status_code, 204)

    def test_dashboard_view(self):
        view = resolve('/accounts/')
        self.assertEquals(view.func, views.dashboard)

Você deve fazer log-in para responder a esta pergunta.

Esta não é a resposta que você está procurando? Pesquise outras perguntas com a tag .