此文主要講解pycharm進行單元測試的配置
單元測試框架爲pytest,安裝命令爲
pip install pytest
def add(a, b):
if isinstance(a, str):
return a + '+' + b
return a + b
創建文件夾test,並建立測試文件 test.py
from func.addfunc import add
def test_add():
assert add(1, 1) == 2
assert add('1', '2') == '1+2'
配置pycharm,配置好之後確定
先配置pytest
然後配置Coverage
選中test文件夾,右鍵,選擇 Run ‘pytest in test’ with Coverage,然後點擊Coverage的標籤頁,便可看到覆蓋率統計