{"id":1392,"date":"2023-07-10T13:21:01","date_gmt":"2023-07-10T20:21:01","guid":{"rendered":"https:\/\/www.ewert-technologies.ca\/blogs\/?p=1392"},"modified":"2023-07-10T13:21:04","modified_gmt":"2023-07-10T20:21:04","slug":"custom-asserts-for-use-with-result-type-in-kotlin","status":"publish","type":"post","link":"https:\/\/www.ewert-technologies.ca\/blogs\/technology\/custom-asserts-for-use-with-result-type-in-kotlin\/","title":{"rendered":"Custom Asserts for use with Result<V, E> type in Kotlin"},"content":{"rendered":"\n<p>I have recently been working on a project written in <a href=\"https:\/\/kotlinlang.org\/\" target=\"_blank\" rel=\"noreferrer noopener\">Kotlin<\/a>, and for unit testing, I decided to go with <a href=\"https:\/\/github.com\/willowtreeapps\/assertk\" target=\"_blank\" rel=\"noreferrer noopener\">assertk<\/a> as my assertion library. I have used <a href=\"https:\/\/assertj.github.io\/doc\/\" target=\"_blank\" rel=\"noreferrer noopener\">AssertJ<\/a> in the past and like the fluent syntax provided by both. With assertk, you can write assertions like:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: java; title: ; notranslate\" title=\"\">\nassertThat(person.name).isEqualTo(&quot;Alice&quot;)\nassertThat(person).prop(Person::age).isEqualTo(20)\nassertThat(person.isActive).isTrue()\nassertThat(employeeList).hasSize(5)\n<\/pre><\/div>\n\n\n<p>In this project, I am also using <a href=\"https:\/\/betterprogramming.pub\/typed-error-handling-in-kotlin-11ff25882880\" target=\"_blank\" rel=\"noreferrer noopener\">Typed Errors<\/a> (instead of Exceptions) for error handling and decided to use the <a href=\"https:\/\/github.com\/michaelbull\/kotlin-result\" target=\"_blank\" rel=\"noreferrer noopener\">kotlin-result<\/a> library for this. This library provides a <code>Result&lt;V, E><\/code> type, so when a function can produce an error it returns a <code>Result<\/code>, that holds either the value or the error. Below is a simple example:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nfun getUser(credential: Credential, id: Int): Result&amp;lt;User, Error&gt; {\n  val success = checkCredential(credential)\n  return if (success) {\n    Ok(User(id))\n  } else {\n    Err(Error(msg = &quot;Could not create a user!&quot;)\n  }\n}\n<\/pre><\/div>\n\n\n<p>See the <a href=\"https:\/\/github.com\/michaelbull\/kotlin-result\" target=\"_blank\" rel=\"noreferrer noopener\">kotlin-result<\/a> documentation for more examples.<\/p>\n\n\n\n<p>While writing unit tests for functions like this I realized it would be helpful if there were asserts that I could use to check whether the <code>Result<\/code> was <code>Ok<\/code> or <code>Err<\/code>. Luckily, assertk provides a mechanism to create custom asserts and so I created the following <code>Assert<\/code>s to work with kotlin-result <code>Result&lt;V, E><\/code> types.<\/p>\n\n\n\n<p>This first <code>Assert<\/code> checks that a Result is the <code>Ok<\/code> (i.e. success) value.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: java; title: ; notranslate\" title=\"\">\n\/**\n * Asserts that a &#x5B;Result] is Ok\n *\/\nfun &lt;V, E&gt; Assert&lt;Result&lt;V, E&gt;&gt;.isOk() = given { actual -&gt;\n  if (actual !is Ok) {\n    expected(&quot;$actual to be Result.Ok}&quot;)\n  }\n}\n\n\/\/ Example\nval userResult: Result&lt;User, Error&gt; = getUser()\nassertThat(userResult).isOk\n<\/pre><\/div>\n\n\n<p>The second <code>Assert<\/code> asserts that the Result is the <code>Err<\/code> value (i.e. failure case)<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: java; title: ; notranslate\" title=\"\">\n\/**\n * Asserts that a &#x5B;Result] is an Err\n *\/\nfun &lt;V, E&gt; Assert&lt;Result&lt;V, E&gt;&gt;.isErr() = given { actual -&gt;\n  if (actual !is Err) {\n    expected(&quot;${show(actual)} to be Result.Err&quot;)\n  }\n}\n\n\/\/ Example that is expected to give an error:\nval userResult: Result&lt;User, Error&gt; = getUser()\nassertThat(userResult).isErr\n<\/pre><\/div>\n\n\n<p>Sometimes it is useful to assert something on the value after checking the <code>Result<\/code>, so I also created the following, that allows you to chain additional asserts after making the initial assert:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: java; title: ; notranslate\" title=\"\">\n\/**\n * Asserts that a &#x5B;Result] is Ok, and then chains the Ok result\n * so further asserts can be done on the Ok Value\n *\/\nfun &lt;V, E&gt; Assert&lt;Result&lt;V, E&gt;&gt;.isOkAnd(): Assert&lt;V&gt; = transform(appendName(&quot;Result.Ok value&quot;, &quot;.&quot;)) { actual -&gt;\n  if (actual is Ok) {\n    actual.value\n  } else {\n    expected(&quot;${show(actual)} to be Result.Ok}&quot;)\n  }\n}\n\n\/\/ Example\nval userResult&lt;User, Errror&gt; = getUser()\nassertThat(userResult).isOkAnd().prop(User::name).isEqualTo(&quot;Alice&quot;)\n<\/pre><\/div>\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: java; title: ; notranslate\" title=\"\">\n\/**\n * Asserts that a &#x5B;Result] is an Err and then chains the Err result\n * so further asserts can be done on the Err Value\n *\/\nfun &lt;V, E&gt; Assert&lt;Result&lt;V, E&gt;&gt;.isErrAnd() = transform { actual -&gt;\n  if (actual is Err) {\n    actual.error\n  } else {\n    expected(&quot;${show(actual)} to be Result.Err&quot;)\n  }\n}\n\n\/\/ Example\nval userResult&lt;User, Error&gt; = getUser()\nassertThat(userResult).isErrAnd().prop(Error::msg).isEqualTo(&quot;Could not find the user!&quot;)\n<\/pre><\/div>\n\n\n<p>If you are using <a href=\"https:\/\/github.com\/willowtreeapps\/assertk\" target=\"_blank\" rel=\"noreferrer noopener\">assertk<\/a> with <a href=\"https:\/\/github.com\/michaelbull\/kotlin-result\" target=\"_blank\" rel=\"noreferrer noopener\">kotlin-result<\/a>, hopefully, you will find these custom assertions helpful. Please feel free to use them in your own code and\/or adapt them as needed. They could also be adapted for other Typed Error mechanisms including the <a href=\"https:\/\/arrow-kt.io\/\" target=\"_blank\" rel=\"noreferrer noopener\">Arrow-Kt<\/a> Either type.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I have recently been working on a project written in Kotlin, and for unit testing, I decided to go with assertk as my assertion library. I have used AssertJ in the past and like the fluent syntax provided by both. With assertk, you can write assertions like: In this project, I am also using Typed [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":1409,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"default","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"default","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[13],"tags":[57,58,59],"class_list":["post-1392","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-technology","tag-kotlin","tag-typed-errors","tag-unit-testing"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Custom Asserts for use with Result type in Kotlin - Ewert Technologies Blog<\/title>\n<meta name=\"description\" content=\"This article gives examples of how to use custom assertions in assertk, to assert on typed errors that use the kotlin-result Result type.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.ewert-technologies.ca\/blogs\/technology\/custom-asserts-for-use-with-result-type-in-kotlin\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Custom Asserts for use with Result type in Kotlin - Ewert Technologies Blog\" \/>\n<meta property=\"og:description\" content=\"This article gives examples of how to use custom assertions in assertk, to assert on typed errors that use the kotlin-result Result type.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.ewert-technologies.ca\/blogs\/technology\/custom-asserts-for-use-with-result-type-in-kotlin\/\" \/>\n<meta property=\"og:site_name\" content=\"Ewert Technologies Blog\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/EwertTechnologies\" \/>\n<meta property=\"article:author\" content=\"https:\/\/www.facebook.com\/EwertTechnologies\" \/>\n<meta property=\"article:published_time\" content=\"2023-07-10T20:21:01+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-07-10T20:21:04+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.ewert-technologies.ca\/blogs\/wp-content\/uploads\/kotlin-logo-250.png\" \/>\n\t<meta property=\"og:image:width\" content=\"250\" \/>\n\t<meta property=\"og:image:height\" content=\"250\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Victor Ewert\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@EwertTech\" \/>\n<meta name=\"twitter:site\" content=\"@EwertTech\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Victor Ewert\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.ewert-technologies.ca\/blogs\/technology\/custom-asserts-for-use-with-result-type-in-kotlin\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.ewert-technologies.ca\/blogs\/technology\/custom-asserts-for-use-with-result-type-in-kotlin\/\"},\"author\":{\"name\":\"Victor Ewert\",\"@id\":\"https:\/\/www.ewert-technologies.ca\/blogs\/#\/schema\/person\/83341249e0e6fd8678a5f2cda46f92a0\"},\"headline\":\"Custom Asserts for use with Result type in Kotlin\",\"datePublished\":\"2023-07-10T20:21:01+00:00\",\"dateModified\":\"2023-07-10T20:21:04+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.ewert-technologies.ca\/blogs\/technology\/custom-asserts-for-use-with-result-type-in-kotlin\/\"},\"wordCount\":267,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/www.ewert-technologies.ca\/blogs\/#organization\"},\"image\":{\"@id\":\"https:\/\/www.ewert-technologies.ca\/blogs\/technology\/custom-asserts-for-use-with-result-type-in-kotlin\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/i0.wp.com\/www.ewert-technologies.ca\/blogs\/wp-content\/uploads\/kotlin-logo-250.png?fit=250%2C250&ssl=1\",\"keywords\":[\"Kotlin\",\"Typed Errors\",\"Unit Testing\"],\"articleSection\":[\"Technology News and Tips\"],\"inLanguage\":\"en-CA\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/www.ewert-technologies.ca\/blogs\/technology\/custom-asserts-for-use-with-result-type-in-kotlin\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.ewert-technologies.ca\/blogs\/technology\/custom-asserts-for-use-with-result-type-in-kotlin\/\",\"url\":\"https:\/\/www.ewert-technologies.ca\/blogs\/technology\/custom-asserts-for-use-with-result-type-in-kotlin\/\",\"name\":\"Custom Asserts for use with Result type in Kotlin - Ewert Technologies Blog\",\"isPartOf\":{\"@id\":\"https:\/\/www.ewert-technologies.ca\/blogs\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.ewert-technologies.ca\/blogs\/technology\/custom-asserts-for-use-with-result-type-in-kotlin\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.ewert-technologies.ca\/blogs\/technology\/custom-asserts-for-use-with-result-type-in-kotlin\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/i0.wp.com\/www.ewert-technologies.ca\/blogs\/wp-content\/uploads\/kotlin-logo-250.png?fit=250%2C250&ssl=1\",\"datePublished\":\"2023-07-10T20:21:01+00:00\",\"dateModified\":\"2023-07-10T20:21:04+00:00\",\"description\":\"This article gives examples of how to use custom assertions in assertk, to assert on typed errors that use the kotlin-result Result type.\",\"breadcrumb\":{\"@id\":\"https:\/\/www.ewert-technologies.ca\/blogs\/technology\/custom-asserts-for-use-with-result-type-in-kotlin\/#breadcrumb\"},\"inLanguage\":\"en-CA\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.ewert-technologies.ca\/blogs\/technology\/custom-asserts-for-use-with-result-type-in-kotlin\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-CA\",\"@id\":\"https:\/\/www.ewert-technologies.ca\/blogs\/technology\/custom-asserts-for-use-with-result-type-in-kotlin\/#primaryimage\",\"url\":\"https:\/\/i0.wp.com\/www.ewert-technologies.ca\/blogs\/wp-content\/uploads\/kotlin-logo-250.png?fit=250%2C250&ssl=1\",\"contentUrl\":\"https:\/\/i0.wp.com\/www.ewert-technologies.ca\/blogs\/wp-content\/uploads\/kotlin-logo-250.png?fit=250%2C250&ssl=1\",\"width\":250,\"height\":250,\"caption\":\"Kotlin Logo\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.ewert-technologies.ca\/blogs\/technology\/custom-asserts-for-use-with-result-type-in-kotlin\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.ewert-technologies.ca\/blogs\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Custom Asserts for use with Result type in Kotlin\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.ewert-technologies.ca\/blogs\/#website\",\"url\":\"https:\/\/www.ewert-technologies.ca\/blogs\/\",\"name\":\"Ewert Technologies Blog\",\"description\":\"Welcome to the Ewert Technologies Blog Site\",\"publisher\":{\"@id\":\"https:\/\/www.ewert-technologies.ca\/blogs\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.ewert-technologies.ca\/blogs\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-CA\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/www.ewert-technologies.ca\/blogs\/#organization\",\"name\":\"Ewert Technologies\",\"url\":\"https:\/\/www.ewert-technologies.ca\/blogs\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-CA\",\"@id\":\"https:\/\/www.ewert-technologies.ca\/blogs\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/i1.wp.com\/www.ewert-technologies.ca\/blogs\/wp-content\/uploads\/logo_200.png?fit=200%2C79&ssl=1\",\"contentUrl\":\"https:\/\/i1.wp.com\/www.ewert-technologies.ca\/blogs\/wp-content\/uploads\/logo_200.png?fit=200%2C79&ssl=1\",\"width\":200,\"height\":79,\"caption\":\"Ewert Technologies\"},\"image\":{\"@id\":\"https:\/\/www.ewert-technologies.ca\/blogs\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/EwertTechnologies\",\"https:\/\/x.com\/EwertTech\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.ewert-technologies.ca\/blogs\/#\/schema\/person\/83341249e0e6fd8678a5f2cda46f92a0\",\"name\":\"Victor Ewert\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-CA\",\"@id\":\"https:\/\/www.ewert-technologies.ca\/blogs\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/www.ewert-technologies.ca\/blogs\/wp-content\/litespeed\/avatar\/9de67af6c08020159b0c49938492aada.jpg?ver=1776826808\",\"contentUrl\":\"https:\/\/www.ewert-technologies.ca\/blogs\/wp-content\/litespeed\/avatar\/9de67af6c08020159b0c49938492aada.jpg?ver=1776826808\",\"caption\":\"Victor Ewert\"},\"description\":\"I am Victor Ewert, an Independent Software Developer and owner of Ewert Technologies. In the past I have worked as a Software Tester including working on Software Test automation. My current technology interests include Java, JavaFX, Kotlin, Swift, Privacy and Security, and Mobile App development.\",\"sameAs\":[\"https:\/\/www.ewert-technologies.ca\/home\",\"https:\/\/www.facebook.com\/EwertTechnologies\",\"https:\/\/www.linkedin.com\/in\/vewert\",\"https:\/\/x.com\/EwertTech\"]}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Custom Asserts for use with Result type in Kotlin - Ewert Technologies Blog","description":"This article gives examples of how to use custom assertions in assertk, to assert on typed errors that use the kotlin-result Result type.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.ewert-technologies.ca\/blogs\/technology\/custom-asserts-for-use-with-result-type-in-kotlin\/","og_locale":"en_US","og_type":"article","og_title":"Custom Asserts for use with Result type in Kotlin - Ewert Technologies Blog","og_description":"This article gives examples of how to use custom assertions in assertk, to assert on typed errors that use the kotlin-result Result type.","og_url":"https:\/\/www.ewert-technologies.ca\/blogs\/technology\/custom-asserts-for-use-with-result-type-in-kotlin\/","og_site_name":"Ewert Technologies Blog","article_publisher":"https:\/\/www.facebook.com\/EwertTechnologies","article_author":"https:\/\/www.facebook.com\/EwertTechnologies","article_published_time":"2023-07-10T20:21:01+00:00","article_modified_time":"2023-07-10T20:21:04+00:00","og_image":[{"width":250,"height":250,"url":"https:\/\/www.ewert-technologies.ca\/blogs\/wp-content\/uploads\/kotlin-logo-250.png","type":"image\/png"}],"author":"Victor Ewert","twitter_card":"summary_large_image","twitter_creator":"@EwertTech","twitter_site":"@EwertTech","twitter_misc":{"Written by":"Victor Ewert","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.ewert-technologies.ca\/blogs\/technology\/custom-asserts-for-use-with-result-type-in-kotlin\/#article","isPartOf":{"@id":"https:\/\/www.ewert-technologies.ca\/blogs\/technology\/custom-asserts-for-use-with-result-type-in-kotlin\/"},"author":{"name":"Victor Ewert","@id":"https:\/\/www.ewert-technologies.ca\/blogs\/#\/schema\/person\/83341249e0e6fd8678a5f2cda46f92a0"},"headline":"Custom Asserts for use with Result type in Kotlin","datePublished":"2023-07-10T20:21:01+00:00","dateModified":"2023-07-10T20:21:04+00:00","mainEntityOfPage":{"@id":"https:\/\/www.ewert-technologies.ca\/blogs\/technology\/custom-asserts-for-use-with-result-type-in-kotlin\/"},"wordCount":267,"commentCount":0,"publisher":{"@id":"https:\/\/www.ewert-technologies.ca\/blogs\/#organization"},"image":{"@id":"https:\/\/www.ewert-technologies.ca\/blogs\/technology\/custom-asserts-for-use-with-result-type-in-kotlin\/#primaryimage"},"thumbnailUrl":"https:\/\/i0.wp.com\/www.ewert-technologies.ca\/blogs\/wp-content\/uploads\/kotlin-logo-250.png?fit=250%2C250&ssl=1","keywords":["Kotlin","Typed Errors","Unit Testing"],"articleSection":["Technology News and Tips"],"inLanguage":"en-CA","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.ewert-technologies.ca\/blogs\/technology\/custom-asserts-for-use-with-result-type-in-kotlin\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.ewert-technologies.ca\/blogs\/technology\/custom-asserts-for-use-with-result-type-in-kotlin\/","url":"https:\/\/www.ewert-technologies.ca\/blogs\/technology\/custom-asserts-for-use-with-result-type-in-kotlin\/","name":"Custom Asserts for use with Result type in Kotlin - Ewert Technologies Blog","isPartOf":{"@id":"https:\/\/www.ewert-technologies.ca\/blogs\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.ewert-technologies.ca\/blogs\/technology\/custom-asserts-for-use-with-result-type-in-kotlin\/#primaryimage"},"image":{"@id":"https:\/\/www.ewert-technologies.ca\/blogs\/technology\/custom-asserts-for-use-with-result-type-in-kotlin\/#primaryimage"},"thumbnailUrl":"https:\/\/i0.wp.com\/www.ewert-technologies.ca\/blogs\/wp-content\/uploads\/kotlin-logo-250.png?fit=250%2C250&ssl=1","datePublished":"2023-07-10T20:21:01+00:00","dateModified":"2023-07-10T20:21:04+00:00","description":"This article gives examples of how to use custom assertions in assertk, to assert on typed errors that use the kotlin-result Result type.","breadcrumb":{"@id":"https:\/\/www.ewert-technologies.ca\/blogs\/technology\/custom-asserts-for-use-with-result-type-in-kotlin\/#breadcrumb"},"inLanguage":"en-CA","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.ewert-technologies.ca\/blogs\/technology\/custom-asserts-for-use-with-result-type-in-kotlin\/"]}]},{"@type":"ImageObject","inLanguage":"en-CA","@id":"https:\/\/www.ewert-technologies.ca\/blogs\/technology\/custom-asserts-for-use-with-result-type-in-kotlin\/#primaryimage","url":"https:\/\/i0.wp.com\/www.ewert-technologies.ca\/blogs\/wp-content\/uploads\/kotlin-logo-250.png?fit=250%2C250&ssl=1","contentUrl":"https:\/\/i0.wp.com\/www.ewert-technologies.ca\/blogs\/wp-content\/uploads\/kotlin-logo-250.png?fit=250%2C250&ssl=1","width":250,"height":250,"caption":"Kotlin Logo"},{"@type":"BreadcrumbList","@id":"https:\/\/www.ewert-technologies.ca\/blogs\/technology\/custom-asserts-for-use-with-result-type-in-kotlin\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.ewert-technologies.ca\/blogs\/"},{"@type":"ListItem","position":2,"name":"Custom Asserts for use with Result type in Kotlin"}]},{"@type":"WebSite","@id":"https:\/\/www.ewert-technologies.ca\/blogs\/#website","url":"https:\/\/www.ewert-technologies.ca\/blogs\/","name":"Ewert Technologies Blog","description":"Welcome to the Ewert Technologies Blog Site","publisher":{"@id":"https:\/\/www.ewert-technologies.ca\/blogs\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.ewert-technologies.ca\/blogs\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-CA"},{"@type":"Organization","@id":"https:\/\/www.ewert-technologies.ca\/blogs\/#organization","name":"Ewert Technologies","url":"https:\/\/www.ewert-technologies.ca\/blogs\/","logo":{"@type":"ImageObject","inLanguage":"en-CA","@id":"https:\/\/www.ewert-technologies.ca\/blogs\/#\/schema\/logo\/image\/","url":"https:\/\/i1.wp.com\/www.ewert-technologies.ca\/blogs\/wp-content\/uploads\/logo_200.png?fit=200%2C79&ssl=1","contentUrl":"https:\/\/i1.wp.com\/www.ewert-technologies.ca\/blogs\/wp-content\/uploads\/logo_200.png?fit=200%2C79&ssl=1","width":200,"height":79,"caption":"Ewert Technologies"},"image":{"@id":"https:\/\/www.ewert-technologies.ca\/blogs\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/EwertTechnologies","https:\/\/x.com\/EwertTech"]},{"@type":"Person","@id":"https:\/\/www.ewert-technologies.ca\/blogs\/#\/schema\/person\/83341249e0e6fd8678a5f2cda46f92a0","name":"Victor Ewert","image":{"@type":"ImageObject","inLanguage":"en-CA","@id":"https:\/\/www.ewert-technologies.ca\/blogs\/#\/schema\/person\/image\/","url":"https:\/\/www.ewert-technologies.ca\/blogs\/wp-content\/litespeed\/avatar\/9de67af6c08020159b0c49938492aada.jpg?ver=1776826808","contentUrl":"https:\/\/www.ewert-technologies.ca\/blogs\/wp-content\/litespeed\/avatar\/9de67af6c08020159b0c49938492aada.jpg?ver=1776826808","caption":"Victor Ewert"},"description":"I am Victor Ewert, an Independent Software Developer and owner of Ewert Technologies. In the past I have worked as a Software Tester including working on Software Test automation. My current technology interests include Java, JavaFX, Kotlin, Swift, Privacy and Security, and Mobile App development.","sameAs":["https:\/\/www.ewert-technologies.ca\/home","https:\/\/www.facebook.com\/EwertTechnologies","https:\/\/www.linkedin.com\/in\/vewert","https:\/\/x.com\/EwertTech"]}]}},"jetpack_publicize_connections":[],"jetpack_featured_media_url":"https:\/\/i0.wp.com\/www.ewert-technologies.ca\/blogs\/wp-content\/uploads\/kotlin-logo-250.png?fit=250%2C250&ssl=1","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.ewert-technologies.ca\/blogs\/wp-json\/wp\/v2\/posts\/1392","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.ewert-technologies.ca\/blogs\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.ewert-technologies.ca\/blogs\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.ewert-technologies.ca\/blogs\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.ewert-technologies.ca\/blogs\/wp-json\/wp\/v2\/comments?post=1392"}],"version-history":[{"count":21,"href":"https:\/\/www.ewert-technologies.ca\/blogs\/wp-json\/wp\/v2\/posts\/1392\/revisions"}],"predecessor-version":[{"id":1438,"href":"https:\/\/www.ewert-technologies.ca\/blogs\/wp-json\/wp\/v2\/posts\/1392\/revisions\/1438"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.ewert-technologies.ca\/blogs\/wp-json\/wp\/v2\/media\/1409"}],"wp:attachment":[{"href":"https:\/\/www.ewert-technologies.ca\/blogs\/wp-json\/wp\/v2\/media?parent=1392"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.ewert-technologies.ca\/blogs\/wp-json\/wp\/v2\/categories?post=1392"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.ewert-technologies.ca\/blogs\/wp-json\/wp\/v2\/tags?post=1392"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}