728x90
๋ฐ˜์‘ํ˜•
  1. jUnit : assertArray / asertThrows
  2. checkStyle : ์ฝ”๋”ฉ ์Šคํƒ€์ผ ์ •๋Ÿ‰
  3. Doxygen : ์˜์กด์„ฑ ๋ถ„์„(๋‹ค์ด์–ด๊ทธ๋žจ)

 

# 1. JUnit ํ•œ๋‹จ๊ณ„ ๋” ๋‚˜์•„๊ฐ€๊ธฐ

 

์˜ˆ์™ธ๊ฐ€ ๋ฐœ์ƒํ•˜๋Š”์ง€ ํ™•์ธํ•˜๊ณ  ๊ทธ ๋ฉ”์„ธ์ง€๋ฅผ exception์— ์ €์žฅํ•ด์„œ ์šฐ๋ฆฌ๊ฐ€ ์›ํ•˜๋Š” ์—๋Ÿฌ ๋ฌธ์ž์™€ ์ผ์น˜ํ•˜๋Š”์ง€๊นŒ์ง€ ํ™•์ธํ•˜๊ธฐ!

@Test
	void testDivide() throws Exception {
//		assertEquals(0.5, calculator.divide(2.0, 4.0));
		assertThrows(Exception.class, () -> 
			calculator.divide(4, 0), "0 ์˜ˆ์™ธ ์ฒ˜๋ฆฌ ๋ฐœ์ƒ"
		);
		// calculator.divide(4, 0)์‹คํ–‰ ์‹œ, Exception ์—ฌ๋ถ€๋งŒ ํ™•์ธ
	}	
	
	// ์—ฌ๋ถ€๋งŒ ํ™•์ธํ•˜๋Š”๊ฒŒ ์•„๋‹ˆ๋ผ ๋ฌธ์ž๊ฐ€ ๋‚˜์˜ค๋Š”์ง€ ํ™•์ธ
	@Test
	public void testDevide_exception() throws Exception {
		Exception exception = assertThrows(Exception.class, () -> 
		calculator.divide(4, 0), "0 ์˜ˆ์™ธ ์ฒ˜๋ฆฌ ๋ฐœ์ƒ"
		);
		
		assertEquals("Divide Error", exception.getMessage());
	}

 

์ •์  ๋ถ„์„ ์ฝ”๋“œ ๋Œ๋ฆฌ๊ธฐ  : SonarQube(java๋Š” ๋ฌด๋ฃŒ) - pmd, checkstyle

1. ๊ฐœ์ธ์ ์ธ ํด๋” ๋‚ด์—์„œ eclipse, Intellij์—์„œ ๋Œ๋ฆฌ๋ฉด SonarLint

2. git์— ํ†ต์ฒด๋กœ ์˜ฌ๋ ธ์„๋•Œ๋Š” SonarQube(์„œ๋ฒ„) ํšŒ์‚ฌ ์ „์ฒด ๋‚ด๋ถ€์˜ ์ฝ”๋“œ๋ฅผ ๋ณผ ์ˆ˜ ์žˆ์Œ 

3. Jenkins CI/CD์—์„œ buildํ• ๋•Œ SonarQube ์‚ฌ์šฉํ•  ์ˆ˜๋„ ์žˆ์Œ

 

 

JUnit์€ ๋‹จ์œ„ ํ…Œ์ŠคํŠธ๋ฅผ ์œ„ํ•œ ๋„๊ตฌ์ด๊ณ  ์›น/์•ฑ์—์„œ๋Š” ๊ทธ๋ ‡๊ฒŒ ํ•„์ˆ˜์ ์ด์ง€๋Š” ์•Š๋‹ค!!  

 

 

 

# assertArray ์‚ฌ์šฉ!!

 

package com.calc;

import static org.junit.jupiter.api.Assertions.assertArrayEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;

import java.util.Arrays;

import org.junit.jupiter.api.Test;

class CalculatorTest_format {

	Calculator calculator = new Calculator();
	
	// assertEquals : ๊ฐœ๋ณ„ ์š”์†Œ ๊ฒ€์ฆ
	
	@Test
	void testParseInput_individualCheck() throws Exception {
		String[] result = calculator.parseInput("2 + 3");
		assertEquals("2", result[0]);
		assertEquals("+", result[1]);
		assertEquals("3", result[2]);
	}
	
	// assertEquals : List ๋กœ ๊ฒ€์ฆ
	@Test
	void testParseInput_listCheck() throws Exception {
		String[] result = calculator.parseInput("2 + 3");
		assertEquals(Arrays.asList("2", "+", "3"), Arrays.asList(result));
	}
	
	// assertEquals
	@Test
	void testParseInput_array() throws Exception {
		String[] result = calculator.parseInput("2 + 3");
		assertArrayEquals(new String[] {"2", "+", "3"}, result, "๋ฐฐ์—ด์ด ์˜ˆ์ƒ ๊ฐ’๊ณผ ๋‹ค๋ฆ…๋‹ˆ๋‹ค");
	}
	
	// null, empty ์ฒ˜๋ฆฌ ์—ฌ๋ถ€ ํ™•์ธ
	@Test
	void testParseInput_nullAndEmpty() throws Exception {
		Exception nullException = 
				assertThrows(Exception.class, () -> 
						calculator.parseInput(null));
		assertEquals("null์€ ์ž…๋ ฅ ๋ถˆ๊ฐ€", nullException.getMessage());
	}
}

 

 

# checkStyle ์ ์šฉํ•˜๊ธฐ

marketplace์—์„œ ๋‹ค์šด

 

checkstyle ์„ค์ •

 

๋…ธ๋ž‘์ด๋Š” ์ฃผ์˜~~ ๋นจ๊ฐ•๋งŒ ์•„๋‹ˆ๋ฉด ๋œ๋‹ค~~

 


# doxygen (์˜์กด๊ด€๊ณ„ ํŒŒ์•… ๋ถ„์„ํ•˜๊ณ  ์‹œ๊ฐํ™”ํ•˜์ง€๋งŒ ๊ฐ„๋žตํ•จ)

 

์˜์กด์„ฑ ๋ถ„์„

  • ๊ฐœ์š”
    • ํ•จ์ˆ˜ ๋ณ€์ˆ˜์˜ ํ˜ธ์ถœ๊ด€๊ณ„๋ฅผ ๋ถ„์„ํ•˜๋Š” ๋„๊ตฌ
    • ๋„๊ตฌ๊ฐ€ ์ถ”๊ตฌํ•˜๋Š” ๋ฐฉํ–ฅ์— ๋”ฐ๋ผ ํŒจํ‚ค์ง€ ํด๋ž˜์Šค(ํŒŒ์ผ) ํ•จ์ˆ˜ ๋‹จ์œ„๋กœ ํ‘œํ˜„
  • ๋ชฉ์ 
    • ์•„ํ‚คํ…์ฒ˜ ๊ตฌ์กฐ์—์„œ ์„œ๋ธŒ ์‹œ์Šคํ…œ ๊ฐ„์˜ ์˜์กด์ด  ์ ์ ˆํ•œ์ง€ ํ™•์ธ
      • ์„œ๋ธŒ ์‹œ์Šคํ…œ ๋ ˆ์ด์–ด์—์„œ ๊ฐ ๋ ˆ์ด์–ด ๊ฐ„ ํ˜ธ์ถœ๊ด€๊ณ„
      • ์„œ๋ธŒ ์‹œ์Šคํ…œ ๋ ˆ๋ฒจ์—์„œ ๊ฐ ๋ ˆ๋ฒจ ๊ฐ„ ํ˜ธ์ถœ ๊ด€๊ณ„
      • ์›ํ˜•์˜์กด์„ฑ(์ƒํ˜ธ ์ฐธ์กฐ)๊ด€๊ณ„
    • ๊ฐ์ฒด์ง€ํ–ฅ์— ํŠนํ™”๋˜์–ด, ์ถ”์ƒํ™”์™€ ๊ตฌ์ œ์ดค์˜ ์ •๋„๋ฅผ ํ™•์ธ 

https://www.doxygen.nl/download.html#google_vignette

 

Doxygen download

Download Doxygen Free and open source software

www.doxygen.nl

 

 

# graphvie(Doxygen์˜ ๋ถ„์„ ๊ฒฐ๊ณผ๋ฅผ ์ข‹๊ฒŒ ์‹œ๊ฐํ™” ํ•˜๋Š” ๋„๊ตฌ, ์‚ฐ์ถœ๋ฌผ ์ œ์ถœ์— ์šฉ์ดํ•จ)

https://graphviz.org/download/

 

Download

Source Code Source code packages for the latest stable and development versions of Graphviz are available, along with instructions for anonymous access to the sources using Git. Executable Packages Packages marked with an asterisk(*) are provided by outsid

graphviz.org

 

 

 

Scan recursively : ์˜ต์…˜ ๋‹ค ๋ถ„์„!! ๋ฌด์กฐ๊ฑด ๋ˆŒ๋Ÿฌ!!

 

๋ชจ๋“  ์—”ํ‹ฐํ‹ฐ ์ง€์› / Java ์ง€์›

 

๋„ค๋น„๊ฒŒ์ด์…˜ ๋ฐ” / ๊ฒ€์ƒ‰ ์ถ”๊ฐ€

 

๊ทธ๋ž˜๋น„์ธ ๋ฅผ ๋‹ค์šด ๋ฐ›์€ ์ด์œ  / ์–ด๋–ป๊ฒŒ ํ‘œ์‹œํ• ์ง€๋ฅผ ๋‚˜ํƒ€๋ƒ„

 

 

728x90
๋ฐ˜์‘ํ˜•

+ Recent posts