2014-05-05 42 views
1

我学习测试驱动开发...为什么我的测试没有在我的TestCase子类中运行?

我写了一个测试失败了,但它不是...

(env)glitch:ipals nathann$ ./manage.py test npage/ 
Creating test database for alias 'default'... 

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

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

/我有tests.py:

from django.test import TestCase 
from npage.models import Tip 
import datetime 


# Example 


class TipTester(TestCase): 

    def setUp(self): 
     print dir(self) 
     Tip.objects.create(pk=1, 
          text='Testing', 
          es_text='Probando') 

    def tips_in_spanish(self): 
     my_tip = Tip.objects.get(pk=1) 

     my_tip.set_language('es') 

     self.assertEqual(my_tip.text, 'this does not just say \'Probando\'') 

我在做什么错?我读过this,但我仍然无法弄清楚这里出了什么问题。

+0

我不认为你需要在你运行的命令npage后的正斜杠。 –

+1

显然你可以做很多不同的方法,甚至隔离应用程序本身的测试用例:https://docs.djangoproject.com/en/dev/topics/testing/overview/#running-tests – broinjc

+0

嗯,我刚刚学会了一些新的东西 –

回答

3

你的测试功能启动时需要测试:

def test_tips_in_spanish(self): 

文档here

“当你运行你的测试,测试工具的默认行为是要找到所有的测试用例(即,unittest.TestCase的子类)放在任何名称以test开头的文件中,自动构建一个测试套件,然后运行该套件。“

+1

请注意,问题不在于测试没有失败,而在于它们不是*运行*。 “冉0测试在0.000s” –

+0

谢谢!没有意识到这也是为了功能。 '在任何名称以test开始的文件中' – broinjc

+0

@broinjc没问题! – Alex

相关问题