回答編集履歴

1

追記

2018/03/02 03:04

投稿

episteme
episteme

スコア16614

test CHANGED
@@ -13,3 +13,55 @@
13
13
  を追加し、SetText("ほげほげ") ののち GetText() から "ほげほげ" が得られることをテストします。
14
14
 
15
15
  こんなメソッド要らない/あってはダメなら `#if FOR_TEST ~ #endif` で囲んでおいて、テスト時のみこのコードを有効にすればいいス。
16
+
17
+
18
+
19
+ [追記] protected な例
20
+
21
+
22
+
23
+ ```C#
24
+
25
+ using System;
26
+
27
+
28
+
29
+ public class foo {
30
+
31
+ protected static string text;
32
+
33
+ public static void set(string str) { text = str; }
34
+
35
+ }
36
+
37
+
38
+
39
+ // ↑納品物
40
+
41
+
42
+
43
+ // ↓テスト・コード
44
+
45
+
46
+
47
+ public class for_test : foo {
48
+
49
+ public static string get() { return text; }
50
+
51
+ }
52
+
53
+
54
+
55
+ public class Program {
56
+
57
+ public static void Main() {
58
+
59
+ foo.set("hoge");
60
+
61
+ Console.WriteLine(for_test.get());
62
+
63
+ }
64
+
65
+ }
66
+
67
+ ```