Java, Spring ์ ํ๋ฆฌ์ผ์ด์ ์ ํ ์คํธ ํ๋ ๋ฐฉ๋ฒ๋ค์ ๋ํ ์์
๋จ์ ํ ์คํธ ์์น - F.I.R.S.T
- Fast: ์ ๋ํ ์คํธ๋ ๋นจ๋ผ์ผ ํ๋ค.
- Isolated: ๋ค๋ฅธ ํ ์คํธ์ ์ข ์์ ์ธ ํ ์คํธ๋ ์ ๋ ์์ฑํ์ง ์๋๋ค.
- Repeatable: ํ ์คํธ๋ ์คํํ ๋ ๋ง๋ค ๊ฐ์ ๊ฒฐ๊ณผ๋ฅผ ๋ง๋ค์ด์ผํ๋ค.
- Self-validating: ํ ์คํธ๋ ์ค์ค๋ก ๊ฒฐ๊ณผ๋ฌผ์ ๋ํ ์ณ๊ณ ๊ทธ๋ฆ์ ํ๋จํ ์ ์์ด์ผ ํ๋ค.
- Timely: ์ ๋ ํ ์คํธ๋ production ์ฝ๋๊ฐ ํ ์คํธ๋ฅผ ํต๊ณผํ๊ธฐ ์ง์ ์ ๊ตฌ์ฑ๋์ด์ผ ํ๋ค. ์ด๋ ํ ์คํธ ์ฃผ๋ ๊ฐ๋ฐ(TDD) ๋ฐฉ๋ฒ๋ก ์ ์ ํฉํ ์์น์ด๋ ์ค์ ๋ก ์ ์ฉ๋์ง ์๋ ๊ฒฝ์ฐ๋ ์๋ค.
๋จ์ ํ ์คํธ (unit test), ํตํฉ ํ ์คํธ (integration test), ์ธ์ํ ์คํธ (acceptance test) ๋ฑ ๋ค์ํ ํ ์คํธ๊ฐ ์กด์ฌํ๋ค. ๊ฐ ํ ์คํธ์ ๋ชฉ์ ๊ณผ ์ํฉ์ ๋ง๊ฒ ํ ์คํธ๋ฅผ ๊ตฌ์ฑํ๋ ๊ฒ๋ ์ค์ํ๋ค.
- Assertion ํ์ฉํ ํ ์คํธ ์ฝ๋ ์์ฑ ๋ฐฉ๋ฒ
- Junit 4: @RunWith(Runner), TestRule, MethodRule
- Junit 5: Extension
- Declarative Registration - @ExtendWith({extensionInstanceName}.class)
@ExtendWith({FindSlowTestExtension}.class)
class ReportTest {
...
}- Programmatic Registration - @RegisterExtension
class ReportTest {
@RegisterExtension
static FindSlowTestExtension findSlowTestExtension = new FindSlowTestExtension({THRESHOLD});
}- Automatic Registration - ServiceLoader
ex) junit-platform.properties
junit.jupiter.extensions.autodetection.enabled = true
Mock(๊ฐ์ง ๊ฐ์ฒด)์ ์์ฑ, ๊ด๋ฆฌํ๊ณ ๊ฒ์ฆํ์ฌ ๋จ์ ํ ์คํธ๋ฅผ ์ํ ํ๋ ์์ํฌ
- ์ปจํธ๋กค ํ๊ธฐ ์ด๋ ค์ด ๋ถ๋ถ์ Mock ๊ฐ์ฒด๋ก ๋์ฒดํด ํ ์คํธํ๋ ค๋ ๋ถ๋ถ์ ์ง์คํ ์ ์๋ค (ex. payment, external API, ...)
- ๊ฐํน ๋ณต์กํ ์ ์๋ ์์กด์ฑ์ ๊ฐ์ํ์ํค๊ณ , ํ ์คํธ ์คํ ์๋๋ฅผ ํฅ์์ํจ๋ค.
Spring Boot 2.2.x ์ด์ ๋ฒ์ spring-boot-starter-test ์์ ์๋์ผ๋ก ์ถ๊ฐ ํด์ค๋ค.
spring-boot-starter-test > mockito-core, mockito-junit-jupiter๋ง์ฝ ์๋ค๋ฉด (Spring Boot๋ฅผ ์ฌ์ฉํ์ง ์๊ฑฐ๋), maven repo ์์ ์๋ dependency๋ฅผ ์ถ๊ฐํ๋ค.
- gradle > build.gradle
testImplementation 'org.mockito:mockito-core:3.7.0'
testImplementation 'org.mockito:mockito-junit-jupiter:3.7.0'- maven > pom.xml
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>3.7.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-junit-jupiter</artifactId>
<version>3.7.0</version>
<scope>test</scope>
</dependency>- Mockito ๊ณต์ ๋ฌธ์
- ๋งํด ํ์ธ๋ฌ์ ์ ๋ํ ์คํธ์ ๋ํ ๊ณ ์ฐฐ
- mockito argument matchers example
์ฑ๋ฅ ์ธก์ ๋ฐ ๋ถํ ํ
์คํธ ๊ธฐ๋ฅ์ ์ ๊ณตํ๋ ์คํ ์์ค ์๋ฐ ์ ํ๋ฆฌ์ผ์ด์
์ผ๋ก,
CLI ๋ฅผ ์ง์ํ์ฌ CI or CD ํด๊ณผ ์ฐ๋ํ ๋ ํธ๋ฆฌํ๋ฉฐ UI ์ฌ์ฉํ๋ ๊ฒ๋ณด๋ค ๋ฉ๋ชจ๋ฆฌ ๋ฑ ์์คํ
๋ฆฌ์์ค๋ฅผ ์ ๊ฒ ์ฌ์ฉํ๋ค.
** JMeter ๋ ์์คํ ๋ฆฌ์์ค๋ฅผ ์ฌ์ฉํ๊ธฐ ๋๋ฌธ์, ํ ์คํธ ํ๊ณ ์ ํ๋ ์ ํ๋ฆฌ์ผ์ด์ ๊ณผ ์๋ฒ๊ฐ ๋ถ๋ฆฌ๋ ํ๊ฒฝ์์ ํ ์คํธ ํด์ผํ๋ค.
- ์น http, https
- SOAP / REST web service
- FTP
- DataBase (JDBC ์ฌ์ฉ)
- Mail (SMTP, POP3, IMAP)
- etc ...
- Thread Group: ํ ์ค๋ ๋ ๋น ์ ์ ํ๋ช (์ ์ ์ ๊ทธ๋ฃน์ด๋ผ๊ณ ์ดํด ํ๊ณ , ์ ์ ์ ์)
- Sampler: ์ด๋ค ์ ์ ๊ฐ ํด์ผํ๋ ์ก์ (HTTP ์์ฒญ ๊ฐ์ ๊ฒ๋ค์ ํ๋์ sampler ๋ผ๊ณ ๋ณธ๋ค.)
- Listener: ์๋ต์ ๋ฐ์์ ํ ์ผ (๋ฆฌํฌํ , ๊ฒ์ฆ, ๊ทธ๋ํ ๊ทธ๋ฆฌ๊ธฐ ๋ฑ)
- Configuration: Sampler ๊ฐ ์ฌ์ฉํ ์ค์ ๊ฐ (HTTP header, Cookie, JDBC connection ...)
- Assertion: ์๋ต์ด ์ฑ๊ณต์ ์ธ์ง ํ์ธํ๋ ๋ฐฉ๋ฒ
- Binary ์์ถ ํ์ผ ๋ค์ด๋ก๋ [http://jmeter.apache.org/download_jmeter.cgi ]
Binarires > Download
apache-jmeter-5.4.zip> Unzip download file
$ cd Download/apache-jmeter-5.4
$ cd bin ./jmeter- Homebrew ๋ก ์ค์นํ๊ธฐ [https://formulae.brew.sh/formula/jmeter]
$ brew install jmeter
$ brew upgrade jmeter
$ open /usr/local/bin/jmeter - Apache JMeter [https://jmeter.apache.org/]