This file contains hidden or 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
#include "gtest/gtest.h" | |
#include <string> | |
// テスト対象のクラス | |
class MyClass { | |
public: | |
MyClass() {} | |
void SetStr(std::string str) { str_ = str; } |
This file contains hidden or 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
#include "gtest/gtest.h" | |
// 例外クラス | |
class MyError : public std::exception { | |
}; | |
// テスト対象のコード | |
void no_throw() { return; } | |
void throw_error() { throw std::exception(); } | |
void throw_my_error() { throw MyError(); } |
This file contains hidden or 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
#include "gtest/gtest.h" | |
#include <string> | |
// テスト対象のクラス | |
class MyClass { | |
public: | |
// MyClassのコンストラクタ | |
MyClass(std::string str) { |
This file contains hidden or 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
import unittest | |
# テスト結果を管理するTextTestResultを継承したクラスを作成 | |
class VerboseTestResult(unittest.TextTestResult): | |
# サブテスト毎に呼ばれるaddSubTest()をオーバーライド | |
def addSubTest(self, test, subtest, outcome): | |
# 元のaddSubTest()を実行して基本的な処理をさせる | |
super(VerboseTestResult, self).addSubTest(test, subtest, outcome) | |
# 実行数を加算する←new! |
This file contains hidden or 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
import signal | |
import time | |
is_waiting = True | |
def hoge_handler(signum, frame): | |
# 第一引数は受信したシグナルの番号 | |
# 第二引数はシグナルが呼ばれた時のスタックフレーム |
This file contains hidden or 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
import unittest | |
# 適当な例外クラス | |
class HogeError(Exception): | |
def __init__(self, code, message): | |
self.code = code | |
self.message = message | |
def __str__(self): |
This file contains hidden or 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
import unittest | |
import unittest.mock | |
def print_hoge(): | |
print('hoge') | |
class HogeTest(unittest.TestCase): | |
# 組み込み関数にパッチを当てる場合は__main__.*に当てる |
This file contains hidden or 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
def get_joined_path(x, y): | |
return os.path.join(x, y) | |
class MockTest(unittest.TestCase): | |
def test_hoge(self): | |
m = unittest.mock.MagicMock() | |
# モックに戻り値を設定しテストを実行 | |
m.return_value = 'aaaa' |
This file contains hidden or 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
import unittest | |
import unittest.mock | |
import os | |
def print_abspath(x): | |
print(os.path.abspath(x)) | |
class MockTest(unittest.TestCase): |
NewerOlder