質問編集履歴
1
追記修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -15,3 +15,181 @@
|
|
15
15
|
僕のファイル構成がおかしいのでしょうか?
|
16
16
|
|
17
17
|
どうやってファイルを分けるのが正しいのでしょうか。
|
18
|
+
|
19
|
+
|
20
|
+
|
21
|
+
以下のようなファイルを作成しました。
|
22
|
+
|
23
|
+
|
24
|
+
|
25
|
+
```header.hpp
|
26
|
+
|
27
|
+
#pragma once
|
28
|
+
|
29
|
+
#include <iostream>
|
30
|
+
|
31
|
+
|
32
|
+
|
33
|
+
int add(int x, int y);
|
34
|
+
|
35
|
+
|
36
|
+
|
37
|
+
```
|
38
|
+
|
39
|
+
|
40
|
+
|
41
|
+
|
42
|
+
|
43
|
+
```main.cpp
|
44
|
+
|
45
|
+
#include "Header.h"
|
46
|
+
|
47
|
+
#include "class.h"
|
48
|
+
|
49
|
+
|
50
|
+
|
51
|
+
using namespace std;
|
52
|
+
|
53
|
+
|
54
|
+
|
55
|
+
int add(int x, int y)
|
56
|
+
|
57
|
+
{
|
58
|
+
|
59
|
+
return x + y;
|
60
|
+
|
61
|
+
}
|
62
|
+
|
63
|
+
|
64
|
+
|
65
|
+
int main()
|
66
|
+
|
67
|
+
{
|
68
|
+
|
69
|
+
cout << add << endl;
|
70
|
+
|
71
|
+
|
72
|
+
|
73
|
+
MyClass m_c(2);
|
74
|
+
|
75
|
+
|
76
|
+
|
77
|
+
cout << m_c.addA() << endl;
|
78
|
+
|
79
|
+
}
|
80
|
+
|
81
|
+
```
|
82
|
+
|
83
|
+
|
84
|
+
|
85
|
+
```class.hpp
|
86
|
+
|
87
|
+
#pragma once
|
88
|
+
|
89
|
+
|
90
|
+
|
91
|
+
class MyClass
|
92
|
+
|
93
|
+
{
|
94
|
+
|
95
|
+
int _a;
|
96
|
+
|
97
|
+
public:
|
98
|
+
|
99
|
+
MyClass(int);
|
100
|
+
|
101
|
+
~MyClass();
|
102
|
+
|
103
|
+
int addA();
|
104
|
+
|
105
|
+
|
106
|
+
|
107
|
+
private:
|
108
|
+
|
109
|
+
|
110
|
+
|
111
|
+
};
|
112
|
+
|
113
|
+
```
|
114
|
+
|
115
|
+
|
116
|
+
|
117
|
+
```class.cpp
|
118
|
+
|
119
|
+
#include "class.h"
|
120
|
+
|
121
|
+
|
122
|
+
|
123
|
+
MyClass::MyClass(int a)
|
124
|
+
|
125
|
+
{
|
126
|
+
|
127
|
+
_a = a;
|
128
|
+
|
129
|
+
}
|
130
|
+
|
131
|
+
|
132
|
+
|
133
|
+
MyClass::~MyClass()
|
134
|
+
|
135
|
+
{
|
136
|
+
|
137
|
+
}
|
138
|
+
|
139
|
+
|
140
|
+
|
141
|
+
int MyClass::addA() { return _a * 2; }
|
142
|
+
|
143
|
+
```
|
144
|
+
|
145
|
+
|
146
|
+
|
147
|
+
```unittest1.cpp
|
148
|
+
|
149
|
+
#include "stdafx.h"
|
150
|
+
|
151
|
+
#include "CppUnitTest.h"
|
152
|
+
|
153
|
+
|
154
|
+
|
155
|
+
#include "../testUnit/class.h"
|
156
|
+
|
157
|
+
#include "../testUnit/Header.h"
|
158
|
+
|
159
|
+
|
160
|
+
|
161
|
+
using namespace Microsoft::VisualStudio::CppUnitTestFramework;
|
162
|
+
|
163
|
+
|
164
|
+
|
165
|
+
namespace UnitTest1
|
166
|
+
|
167
|
+
{
|
168
|
+
|
169
|
+
TEST_CLASS(UnitTest1)
|
170
|
+
|
171
|
+
{
|
172
|
+
|
173
|
+
public:
|
174
|
+
|
175
|
+
|
176
|
+
|
177
|
+
TEST_METHOD(TestMethod1)
|
178
|
+
|
179
|
+
{
|
180
|
+
|
181
|
+
MyClass c(3);
|
182
|
+
|
183
|
+
|
184
|
+
|
185
|
+
Assert::AreEqual(c.addA(), 6);
|
186
|
+
|
187
|
+
}
|
188
|
+
|
189
|
+
|
190
|
+
|
191
|
+
};
|
192
|
+
|
193
|
+
}
|
194
|
+
|
195
|
+
```
|