LoginSignup
1
2

More than 5 years have passed since last update.

「PyCharm の auto-test が地味に便利」を初心者が試してみた

Posted at

PyCharm の auto-test が地味に便利を初心者が試してみた。
なるほど理解。

  • Create New Projectからtesttestプロジェクトを作成

Location: C:\Users\ymko\PycharmProjects\testtest
interpreter: python3.6.1とか

でCreateをクリック

  • testtestの下にp.pyを作成
p.py
class azurlane(object):
    def favorite_chara(self):
        return 'unicorn'
  • testtestの下にtestsフォルダを作成

p.pyのエディタ画面に戻り、class azurlaneのところにカーソルを合わせて右クリック。
Go totestをクリック。
Create New Test...をクリック。

Target directoryをC:/Users/ymko/PycharmProjects/testtest/tests
test_favorite_charaの左側にチェックを入れてOKをクリック

生成されたものにp.pyからclassをインポートしてテスト内容を追加

test_azurlane.py
from unittest import TestCase

from p import azurlane

class TestAzurlane(TestCase):
    def test_favorite_chara(self):
        a = azurlane()
        self.assertEqual(a.favorite_chara(), 'unicorn')

test_azurlane.pyを開いた状態でCtrl+Shift+F10キーを実行するとテストが実行される

左下側のペインに Toggle auto-test のアイコンがあるので有効にする

p.pyを編集するたびに自動テストが走って便利!

参考

Python3のimport・下位/上位階層のモジュールをインポートしたい【import】【Python3】 - DRYな備忘録

PyCharm の auto-test が地味に便利 - Qiita

PyCharm テストコード自動生成 - Qiita

Pythonでunittestを実行する(初心者用) - Qiita

Creating and running a Python unit test - PyCharm - Confluence

1
2
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
1
2