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/]