본문 바로가기

Spock6

[Spock][Intellij] intellij에 인식되지 않는 문제 Spock 테스트를 짤 때 Specification을 임포트 해주지 않았는데 Intellij에서 이를 인식하지 못했다. 프로젝트 탭을 보면 test/kotlin 은 Test source로 인식이되어 있지만 groovy는 인식이 되지 않았다. groovy 우클릭 > Mark Directory as > Test Sources Root 클릭 이제 Specification이 임포트되지 않았다는 것을 인식하고 자동 임포트도 가능해졌다. 2019. 10. 3.
[Spock][Intellij] Empty test suite intellij spock 테스트 시 Class not found: "~~~Test"Empty test suite. 위와 같은 에러가 발생. Solve 테스트 하고 싶은 클래스에서 cmd(ctrl)+shift+t > Create New Test Testing library: Groovy JUnit Groovy JUnit library를 찾을 수 없다는 경고가 뜨면 Fix를 누른다. 그리고 ok. "File > Invalidate Caches / Restart ..." 이거 눌러도 된다고 하는데 나는 안되서 위와 같은 방법으로 해결했다. 2019. 10. 3.
Spock 테스트 정리 Spock으로 테스트코드를 짜보자 (Spock)[http://kwonnam.pe.kr/wiki/java/spock] spock test 예시 when - then @SpringBootTest class apiServiceSpecTest extends Specification { @Autowired ApiService apiService int productNo = 100 int size = 100 def "getProductNames 테스트"() { when: List result = apiService.getProductNames(productNo, size) then: result[0] == "name1" } } expect expect = when + then def "getProductNames .. 2019. 5. 23.
[spock] Kotlin테스트 ReadOnlyPropertyException error @SpringBootTestclass MemberSpeckTest extends Specification { @Autowired MemberService memberService def "getProfileByMemberId() Test"() { given: def profileService = Mock(ProfileService.class) profileService.getProfileByMemberId(0) >> new ProfileResponse(name: "햄과함께") // error // ... }}Colored by Color Scriptercs 위와 같이 groovy 언어로 테스트 코드를 짰다. data class ProfileResponse( val name: String = "", val.. 2019. 3. 5.
[TEST] spock test example /* kotlin */ // SumService.kotlin@Serviceclass SumService { fun getSum(a: Int, b: Int) = a + b }Colored by Color Scriptercs 위와 같이 숫자 a, b를 입력받아 합을 반환하는 함수가 있다고하자.이 함수를 테스트코드를 작성하여 테스트해보자. // SumServiceSpecTest.groovy @SpringBootTestclass SumServiceSpecTest extends Specification { @Autowired SumService sumService def "getSum 음수 테스트" (){ given: int a = -1 int b = -2 when: int result = sumService.g.. 2019. 1. 11.
[Spock][Error] CannotCreateMockException Spock 테스트 코드를 짜던 중 redisTemplate을 사용하는 코드가 있었다. 1234def "redis 테스트"() { def redisTemplate = Mock(RedisTemplate.class) // 생략}Colored by Color Scriptercs 그래서 위와 같이 redisTemplate을 Mock으로 만들어서 요청이 들어오면 내가 원하는 데이터를 반환하게 만들 생각으로 코드를 짰다. org.spockframework.mock.CannotCreateMockException: Cannot create mock for class org.springframework.data.redis.core.RedisTemplate. Mocking of non-interface types requi.. 2019. 1. 3.