-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[test/README.md] add README for test directory
- Loading branch information
1 parent
9db7f68
commit 69d3d66
Showing
1 changed file
with
42 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
# test | ||
## テストの走らせ方 | ||
1. 全部をテスト | ||
```bash | ||
python test_all.py | ||
``` | ||
2. 個別にテスト | ||
```bash | ||
python test_xxx.py | ||
``` | ||
|
||
## テストのTips | ||
- unittestのパッケージを使用. | ||
- pytestは,catkinとの相性が良くない模様.(devel以下の`__init__.py`の読み込みでエラーが出る) | ||
- テストを作るには,unittest.TestCaseを継承したクラスに,test_xxxという名称のメソッドを定義して作る, | ||
- テストを走らせるには,`unittest.main()`を実行すると,`test_xxx`メソッドを順に実行してくれる. | ||
- assertionは,unittest.TestCaseのメソッドである,assertXXXを利用するとテストが失敗したときに見やすく表示される. | ||
|
||
```python | ||
import unittest | ||
|
||
class TestXXX(unittest.TestCase): | ||
def test_hogehoge(self): | ||
# write test here | ||
x = 1 | ||
self.assertEqual(x,1,'x is {}. not 1'.format(x)) | ||
|
||
if __name__ == '__main__': | ||
unittest.main() | ||
``` | ||
- `unittest.main`はテストが終わると,そのまま`exit`しようとするが,ガーベジコレクションの順番によって時々Segmentation Faultが発生する. | ||
以下のようにテスト終了後に`QtGui.QApplication`の消去を明示的に行うとエラーが消えた. | ||
```python | ||
if __name__ == '__main__': | ||
app = pyqtgraph.Qt.QtGui.QApplication([]) | ||
try: | ||
unittest.main() | ||
finally: | ||
del app | ||
``` | ||
|
||
|