프로그래밍/Kotlin 11

ktlint lint 적용

ktlint 정상혁님이 써주신, kotlin lint를 위한 가이드 문서가 잘 소개되어 있습니다. https://blog.benelog.net/ktlint 해당 방식에서는 크게 보면 총 2가지의 방식을 설명하고 있습니다. gradle 빌드 설정 IntelliJ 설정 위와 같은 방식 중에서 review repo, point repo에 도입한 방식은 첫번째 방식인 gradle build 설정을 통한 kotlin lint를 도입하였습니다. https://kotlinlang.org/docs/coding-conventions.html kotlin 언어의 coding convention은 kotlin official로 정의를 하고 있는 특정한 규약들이 있습니다. (java의 경우, Google style guide..

kotest 관련 @Transactional rollback 안되는 이슈

test 코드의 상위 패키지 레벨에 아래 설정을 넣어준다. object KotestConfig : AbstractProjectConfig() { // rollback 관련 동작 안해서 아래 설정 추가 override fun extensions() = listOf(SpringTestExtension(SpringTestLifecycleMode.Root)) } https://kotest.io/docs/framework/project-config.html Project Level Config | Kotest Kotest is flexible and has many ways to configure tests, such as configuring the order of tests inside a spec, or h..

Kapt 관련 오류시 참조 (superclass access check failed)

superclass access check failed: class org.jetbrains.kotlin.kapt3.base.javac.KaptJavaCompiler (in unnamed module @0x37be58b7) cannot access class cohttp://m.sun.tools.javac.main.JavaCompiler (in module jdk.compiler) because module jdk.compiler does not export cohttp://m.sun.tools.javac.main to unnamed module @0x37be58b7 위와 같은 오류가 발생하길래 뭔가 했더니, Java9 이후부터 모듈 시스템이 등장 했는데, 이때문에 이런 오류가 발생하는 것 같다. JDK..

kotlin + junit의 생성자 주입시 오류

kotlin의 경우 생성자 주입을 그냥 하게 되면, 오류가 발생하게 되는데, 아래처럼 해결 하는 방법이 있다. 1. @Autowired constuctor를 사용하는 방법 class SimpleServiceTest @Autowired constructor ( val simpleService: SimpleService ) { @Test fun `이렇게 하면 결과가 나온다`() { } } 2. @TestConstructor(autowireMode = TestConstructor.AutowireMode.ALL) 를 활용하는 방법 @TestConstructor(autowireMode = TestConstructor.AutowireMode.ALL) class SimpleServiceTest ( val simple..

kotest 생성자 bean 주입 오류 - Specs must have a public zero-arg constructor

kotest에서 빈을 생성자 주입으로 쓰려고 하면, Specs must have a public zero-arg constructor 오류가 발생 할 수 있다. 이 때에는 kotest-extension-spring 모듈이 필요로 하다. kotest extension spring 라이브러리가 두개가 검색 되곤 하는데, 헷갈리면 안된다. https://kotest.io/docs/extensions/spring.html Spring | Kotest Kotest offers a Spring extension that allows you to test code that uses the Spring framework for dependency injection. kotest.io 실제 docs를 보면, 1.1.3 ..

Kotest 기본만 알아보자

kotest link: https://kotest.io Kotest is a flexible and elegant multi-platform test framework for Kotlin with extensive assertions and integrated property testing. Testing Styles junit 스타일 지원, JS에서 많이 사용하는 jest와 유사한 테스트 스타일 지원, goovy로 작성하는 spock과도 유사한 형태의 behavior test 스타일도 각기 모두 지원한다. 테스트 스타일 종류 Fun Spec(Scala) Describe Spec(JavaScript framework) Should Spec(kotest) String Spec(kotest) Behavior..

이펙티브 코틀린 3장 재사용성

3장 재사용성 아이템 19 knowledge(의도적인 정보)를 반복하여 사용하지 말라 프로젝트에서 이미 있던 코드를 복사해서 붙여넣고 있다면, 무언가 잘못된 것이다. 프로젝트를 진행할 때 정의한 모든 것이 knowledge 이다. 해당 정보의 종류는 다양한데, 알고리즘의 작동방식, UI의 형태, 우리가 원하는 결과등이 모두 의도적인 정보이며, knowledge이다. 대표적인 knowledge의 두 가지 Logic Common algorithm 모든 것은 변화하고, 변화에 대응을 할 수 있어야 한다. knowledge의 반복은 프로젝트의 확장성을 막고, 쉽게 깨지게 만든다. 그렇기 때문에 knowledge 반복을 줄여주는 도구의 사용이 필요하다. 그런 도구의 예로는 ORM, DAO를 활용 하는 방법이 될 ..

이펙티브 코틀린 2장 가독성

## 2장 가독성 ### 아이템11 가독성을 목표로 설계 하라 ```kotlin if (person != null && person.isAdult) { view.showPerson(person) view.hideProgressWithSuccess() } else { view.showError() view.hiseProgress() } person?.takeIf { it.isAdult } ?.let { view.showPerson(person) view.hideProgressWithSuccess() } ?: run { view.showError() view.hideProgress() } ``` A/B 코드 중에 A 코드가 명확하고, 이해하기가 더 쉽다. B 코드는 코틀린 스러워 보이지만, 오히려 디버깅을 ..

반응형