質問編集履歴
1
追記修正
title
CHANGED
File without changes
|
body
CHANGED
@@ -6,4 +6,93 @@
|
|
6
6
|
としています。
|
7
7
|
テストしようとHeader.hppをincludeしたのですが、おそらく本体がないのでテストできず、cppをincludeしてみてもテストできず、単体テストを書けない状況です。
|
8
8
|
僕のファイル構成がおかしいのでしょうか?
|
9
|
-
どうやってファイルを分けるのが正しいのでしょうか。
|
9
|
+
どうやってファイルを分けるのが正しいのでしょうか。
|
10
|
+
|
11
|
+
以下のようなファイルを作成しました。
|
12
|
+
|
13
|
+
```header.hpp
|
14
|
+
#pragma once
|
15
|
+
#include <iostream>
|
16
|
+
|
17
|
+
int add(int x, int y);
|
18
|
+
|
19
|
+
```
|
20
|
+
|
21
|
+
|
22
|
+
```main.cpp
|
23
|
+
#include "Header.h"
|
24
|
+
#include "class.h"
|
25
|
+
|
26
|
+
using namespace std;
|
27
|
+
|
28
|
+
int add(int x, int y)
|
29
|
+
{
|
30
|
+
return x + y;
|
31
|
+
}
|
32
|
+
|
33
|
+
int main()
|
34
|
+
{
|
35
|
+
cout << add << endl;
|
36
|
+
|
37
|
+
MyClass m_c(2);
|
38
|
+
|
39
|
+
cout << m_c.addA() << endl;
|
40
|
+
}
|
41
|
+
```
|
42
|
+
|
43
|
+
```class.hpp
|
44
|
+
#pragma once
|
45
|
+
|
46
|
+
class MyClass
|
47
|
+
{
|
48
|
+
int _a;
|
49
|
+
public:
|
50
|
+
MyClass(int);
|
51
|
+
~MyClass();
|
52
|
+
int addA();
|
53
|
+
|
54
|
+
private:
|
55
|
+
|
56
|
+
};
|
57
|
+
```
|
58
|
+
|
59
|
+
```class.cpp
|
60
|
+
#include "class.h"
|
61
|
+
|
62
|
+
MyClass::MyClass(int a)
|
63
|
+
{
|
64
|
+
_a = a;
|
65
|
+
}
|
66
|
+
|
67
|
+
MyClass::~MyClass()
|
68
|
+
{
|
69
|
+
}
|
70
|
+
|
71
|
+
int MyClass::addA() { return _a * 2; }
|
72
|
+
```
|
73
|
+
|
74
|
+
```unittest1.cpp
|
75
|
+
#include "stdafx.h"
|
76
|
+
#include "CppUnitTest.h"
|
77
|
+
|
78
|
+
#include "../testUnit/class.h"
|
79
|
+
#include "../testUnit/Header.h"
|
80
|
+
|
81
|
+
using namespace Microsoft::VisualStudio::CppUnitTestFramework;
|
82
|
+
|
83
|
+
namespace UnitTest1
|
84
|
+
{
|
85
|
+
TEST_CLASS(UnitTest1)
|
86
|
+
{
|
87
|
+
public:
|
88
|
+
|
89
|
+
TEST_METHOD(TestMethod1)
|
90
|
+
{
|
91
|
+
MyClass c(3);
|
92
|
+
|
93
|
+
Assert::AreEqual(c.addA(), 6);
|
94
|
+
}
|
95
|
+
|
96
|
+
};
|
97
|
+
}
|
98
|
+
```
|