Skip to content

hyeoni90/java-application-test-way

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

29 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

Java Application Testing Way Example

Java, Spring ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์„ ํ…Œ์ŠคํŠธ ํ•˜๋Š” ๋ฐฉ๋ฒ•๋“ค์— ๋Œ€ํ•œ ์˜ˆ์ œ

Junit5

ํ…Œ์ŠคํŠธ ๊ธฐ๋ณธ ์›์น™

๋‹จ์œ„ ํ…Œ์ŠคํŠธ ์›์น™ - F.I.R.S.T

  • Fast: ์œ ๋‹›ํ…Œ์ŠคํŠธ๋Š” ๋นจ๋ผ์•ผ ํ•œ๋‹ค.
  • Isolated: ๋‹ค๋ฅธ ํ…Œ์ŠคํŠธ์— ์ข…์†์ ์ธ ํ…Œ์ŠคํŠธ๋Š” ์ ˆ๋Œ€ ์ž‘์„ฑํ•˜์ง€ ์•Š๋Š”๋‹ค.
  • Repeatable: ํ…Œ์ŠคํŠธ๋Š” ์‹คํ–‰ํ•  ๋•Œ ๋งˆ๋‹ค ๊ฐ™์€ ๊ฒฐ๊ณผ๋ฅผ ๋งŒ๋“ค์–ด์•ผํ•œ๋‹ค.
  • Self-validating: ํ…Œ์ŠคํŠธ๋Š” ์Šค์Šค๋กœ ๊ฒฐ๊ณผ๋ฌผ์— ๋Œ€ํ•œ ์˜ณ๊ณ  ๊ทธ๋ฆ„์„ ํŒ๋‹จํ•  ์ˆ˜ ์žˆ์–ด์•ผ ํ•œ๋‹ค.
  • Timely: ์œ ๋‹› ํ…Œ์ŠคํŠธ๋Š” production ์ฝ”๋“œ๊ฐ€ ํ…Œ์ŠคํŠธ๋ฅผ ํ†ต๊ณผํ•˜๊ธฐ ์ง์ „์— ๊ตฌ์„ฑ๋˜์–ด์•ผ ํ•œ๋‹ค. ์ด๋Š” ํ…Œ์ŠคํŠธ ์ฃผ๋„ ๊ฐœ๋ฐœ(TDD) ๋ฐฉ๋ฒ•๋ก ์— ์ ํ•ฉํ•œ ์›์น™์ด๋‚˜ ์‹ค์ œ๋กœ ์ ์šฉ๋˜์ง€ ์•Š๋Š” ๊ฒฝ์šฐ๋„ ์žˆ๋‹ค.

๋‹จ์œ„ ํ…Œ์ŠคํŠธ (unit test), ํ†ตํ•ฉ ํ…Œ์ŠคํŠธ (integration test), ์ธ์ˆ˜ํ…Œ์ŠคํŠธ (acceptance test) ๋“ฑ ๋‹ค์–‘ํ•œ ํ…Œ์ŠคํŠธ๊ฐ€ ์กด์žฌํ•œ๋‹ค. ๊ฐ ํ…Œ์ŠคํŠธ์˜ ๋ชฉ์ ๊ณผ ์ƒํ™ฉ์— ๋งž๊ฒŒ ํ…Œ์ŠคํŠธ๋ฅผ ๊ตฌ์„ฑํ•˜๋Š” ๊ฒƒ๋„ ์ค‘์š”ํ•˜๋‹ค.

  • Assertion ํ™œ์šฉํ•œ ํ…Œ์ŠคํŠธ ์ฝ”๋“œ ์ž‘์„ฑ ๋ฐฉ๋ฒ•

Extension Model

  • Junit 4: @RunWith(Runner), TestRule, MethodRule
  • Junit 5: Extension

Register Extension

  1. Declarative Registration - @ExtendWith({extensionInstanceName}.class)
@ExtendWith({FindSlowTestExtension}.class)
class ReportTest {
    ...
}
  1. Programmatic Registration - @RegisterExtension
class ReportTest {
    
    @RegisterExtension
    static FindSlowTestExtension findSlowTestExtension = new FindSlowTestExtension({THRESHOLD});
}
  1. Automatic Registration - ServiceLoader
ex) junit-platform.properties

junit.jupiter.extensions.autodetection.enabled = true

References

Mockito

Mockito ๋ž€?

Mock(๊ฐ€์งœ ๊ฐ์ฒด)์„ ์ƒ์„ฑ, ๊ด€๋ฆฌํ•˜๊ณ  ๊ฒ€์ฆํ•˜์—ฌ ๋‹จ์œ„ ํ…Œ์ŠคํŠธ๋ฅผ ์œ„ํ•œ ํ”„๋ ˆ์ž„์›Œํฌ

์“ฐ๋Š” ์ด์œ ?

  • ์ปจํŠธ๋กค ํ•˜๊ธฐ ์–ด๋ ค์šด ๋ถ€๋ถ„์„ Mock ๊ฐ์ฒด๋กœ ๋Œ€์ฒดํ•ด ํ…Œ์ŠคํŠธํ•˜๋ ค๋Š” ๋ถ€๋ถ„์— ์ง‘์ค‘ํ•  ์ˆ˜ ์žˆ๋‹ค (ex. payment, external API, ...)
  • ๊ฐ„ํ˜น ๋ณต์žกํ•  ์ˆ˜ ์žˆ๋Š” ์˜์กด์„ฑ์„ ๊ฐ„์†Œํ™”์‹œํ‚ค๊ณ , ํ…Œ์ŠคํŠธ ์‹คํ–‰ ์†๋„๋ฅผ ํ–ฅ์ƒ์‹œํ‚จ๋‹ค.

Mockito ์„ค์ •

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>

References

JMeter

์„ฑ๋Šฅ ์ธก์ • ๋ฐ ๋ถ€ํ•˜ ํ…Œ์ŠคํŠธ ๊ธฐ๋Šฅ์„ ์ œ๊ณตํ•˜๋Š” ์˜คํ”ˆ ์†Œ์Šค ์ž๋ฐ” ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์œผ๋กœ, 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: ์‘๋‹ต์ด ์„ฑ๊ณต์ ์ธ์ง€ ํ™•์ธํ•˜๋Š” ๋ฐฉ๋ฒ•

JMeter ์„ค์น˜ ๋ฐ ์‹คํ–‰

  1. 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
  1. Homebrew ๋กœ ์„ค์น˜ํ•˜๊ธฐ [https://formulae.brew.sh/formula/jmeter]
$ brew install jmeter
$ brew upgrade jmeter 
$ open /usr/local/bin/jmeter 

Reference

About

My Java Developer's Way ๐Ÿ› 

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages