0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Djangoテストケースの実行の仕方

Posted at

1. 基本的なテスト実行コマンド

プロジェクトのルートディレクトリ(manage.pyがある場所)で以下を実行:

python manage.py test

これはアプリ全体のテストをすべて実行します。

2. 特定アプリだけをテストする

たとえば api_app だけをテストしたい場合:

python manage.py test api_app

3. 特定のクラスやメソッドだけをテストする

たとえば、api_app.tests モジュールの APITest クラス全体をテスト:

python manage.py test api_app.tests.APITest

特定のメソッドだけをテスト(例:test_memo_create):

python manage.py test api_app.tests.APITest.test_memo_create

4. テストの出力を詳しくしたいとき

出力を詳しく(verbose)したいときは -v 2 を付けます:

python manage.py test -v 2

⚠️ 注意点

テストは自動で テスト用データベース を作成・使用し、終了後に削除されます。
setUp() で作成したユーザーやデータは各テストで初期化されます。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?