Django 1.9。入力フォームが正常に見えないことをテストしたい。ユーザーがトグルメニューボタンを押した場合にのみ、ログインとパスワードの入力要素が表示されます。テストメソッドの順序を保証するためのベストプラクティス
問題は、これがクラスのメソッドに関することです。あるメソッドが別のメソッドの前に実行されていることを確認したい。私はメソッド名に0と1でこの解決策を見つけました。
class FuncTestTablets(TestCase):
@classmethod
def setUpClass(cls):
pass
@classmethod
def tearDownClass(cls):
pass
def test_0_tablets_login_input_form_absent(self):
# At home page with tablet screen size Edith sees no login input element.
## 0 is for stating explicitly that this test goes before the ones with 1 in their name.
self.browser.get('http://localhost:8000')
login_input = self.browser.find_element_by_id('login')
self.assertFalse(login_input.is_displayed(), "Login input element is visible on large devices")
def test_1_tablets_login_input_form_present_when_menu_button_pressed(self):
# At home page Edith presses menu button and login input appears.
## 1 is for stating explicitly that this test goes after the ones with 0 in their name.
menu_button = self.browser.find_element_by_class_name('navbar-toggle')
menu_button.click()
login_input = self.browser.find_element_by_id('login')
self.assertTrue(login_input.is_displayed(), "Login input element is not visible on tablet devices when menu button is pressed.")
これは動作するようです。そのような場合に一般的に知られている方法論があるかどうか教えてください。たぶんいくつかのベストプラクティス。
私はちょうどDjangoを開始しましたが、私の解決策はすぐには最高だとは思いません。
だから私はあなたに尋ねることに決めました。前もって感謝します。