質問編集履歴

1

bugfix and add infomation

2023/02/22 11:37

投稿

yamame01
yamame01

スコア16

test CHANGED
File without changes
test CHANGED
@@ -22,6 +22,17 @@
22
22
  ```
23
23
  テストクラス
24
24
  ```Java
25
+ import org.junit.Test;
26
+ import org.junit.runner.RunWith;
27
+ import org.mockito.InjectMocks;
28
+ import org.powermock.api.mockito.PowerMockito;
29
+ import org.powermock.modules.junit4.PowerMockRunner;
30
+
31
+ import java.lang.reflect.Method;
32
+
33
+ import static org.hamcrest.MatcherAssert.assertThat;
34
+ import static org.hamcrest.Matchers.is;
35
+
25
36
  @RunWith(PowerMockRunner.class)
26
37
  public class TargetClassTest {
27
38
  @InjectMocks
@@ -36,12 +47,30 @@
36
47
  TargetClass spy = PowerMockito.spy(target);
37
48
 
38
49
  try {
39
- method.invoke(spy, 1)
50
+ method.invoke(spy, 1);
40
51
  } catch (MyCustomException e) {
41
- assertThat(e.getErrorMessage(), is("error message02"); // catchできる想定だが、デバックしてもここに来ない
52
+ assertThat(e.getErrorMessage(), is("error message02")); // catchできる想定だが、デバックしてもここに来ない
42
53
  }
43
54
  }
44
55
  }
56
+ ```
57
+ 独自Exception
58
+ ```Java
59
+ @Slf4j
60
+ public class MyCustomException extends RuntimeException {
61
+ private static final Logger logger = LoggerFactory
62
+ .getLogger(OrangeItemLogic.class);
63
+
64
+ public String errorMessage;
65
+
66
+ public MyCustomException(Class clazz, String errorMessage) {
67
+ this.errorMessage = errorMessage;
68
+ logger.error(errorMessage);
69
+ }
70
+
71
+ public String getErrorMessage() {
72
+ return this.errorMessage;
73
+ }
45
74
  ```
46
75
  ### 試したこと
47
76
  ①発生しているExceptionを確認
@@ -82,3 +111,85 @@
82
111
  }
83
112
  }
84
113
  ```
114
+
115
+ ### ツール
116
+ pom.xml(抜粋)
117
+ ```xml
118
+ <dependency>
119
+ <groupId>org.springframework.boot</groupId>
120
+ <artifactId>spring-boot-starter-test</artifactId>
121
+ <scope>test</scope>
122
+ <exclusions>
123
+ <exclusion>
124
+ <groupId>org.slf4j</groupId>
125
+ <artifactId>slf4j-api</artifactId>
126
+ </exclusion>
127
+ </exclusions>
128
+ </dependency>
129
+
130
+ <dependency>
131
+ <groupId>org.assertj</groupId>
132
+ <artifactId>assertj-core</artifactId>
133
+ </dependency>
134
+
135
+ <dependency>
136
+ <groupId>io.takari.junit</groupId>
137
+ <artifactId>takari-cpsuite</artifactId>
138
+ <version>1.2.7</version>
139
+ <scope>test</scope>
140
+ </dependency>
141
+ <dependency>
142
+ <groupId>org.mockito</groupId>
143
+ <artifactId>mockito-core</artifactId>
144
+ <scope>test</scope>
145
+ </dependency>
146
+
147
+ <dependency>
148
+ <groupId>org.powermock</groupId>
149
+ <artifactId>powermock-api-mockito2</artifactId>
150
+ <version>2.0.0-beta.5</version>
151
+ <scope>test</scope>
152
+ </dependency>
153
+ <dependency>
154
+ <groupId>org.powermock</groupId>
155
+ <artifactId>powermock-module-junit4</artifactId>
156
+ <version>2.0.0-beta.5</version>
157
+ <scope>test</scope>
158
+ </dependency>
159
+ <dependency>
160
+ <groupId>uk.co.datumedge</groupId>
161
+ <artifactId>hamcrest-json</artifactId>
162
+ <version>0.2</version>
163
+ <scope>test</scope>
164
+ </dependency>
165
+ <dependency>
166
+ <groupId>org.powermock</groupId>
167
+ <artifactId>powermock-core</artifactId>
168
+ <version>2.0.0-beta.5</version>
169
+ <scope>test</scope>
170
+ </dependency>
171
+ <dependency>
172
+ <groupId>org.easetech</groupId>
173
+ <artifactId>easytest-core</artifactId>
174
+ <version>1.4.0</version>
175
+ <scope>test</scope>
176
+ </dependency>
177
+ <dependency>
178
+ <groupId>org.dbunit</groupId>
179
+ <artifactId>dbunit</artifactId>
180
+ <version>2.5.4</version>
181
+ <scope>test</scope>
182
+ </dependency>
183
+ <dependency>
184
+ <groupId>org.apache.poi</groupId>
185
+ <artifactId>poi</artifactId>
186
+ <version>3.17</version>
187
+ <scope>test</scope>
188
+ </dependency>
189
+
190
+ <dependency>
191
+ <groupId>org.springframework.security</groupId>
192
+ <artifactId>spring-security-test</artifactId>
193
+ <scope>test</scope>
194
+ </dependency>
195
+ ```