1 class PtbReaderTest(tf.test.TestCase):

定義一個python class PtbReaderTest,輸入一個tf.test.TestCase當成參數。

Explain the “setUp” and “tearDown” Python methods used in test cases [1]

是unittest的標準函數

In general, you add all prerequisite steps to setUp and all clean-up steps to tearDown.

When a setUp() method is defined, the test runner will that method prior to each test. Likewise, if tearDown method is defined, the test runner will invoke that method after each test.

3  def setUp(self):
4    self._string_data = "\n".join(
5        [" hello there i am",
6         " rain as day",
7         " want some cheesy puffs ?"])

會在unittest執行前把5~7行的string array放入PtbReaderTest object的hidden variable _string_data

[1] Explain the “setUp” and “tearDown” Python methods used in test cases

results matching ""

    No results matching ""