<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Minimalist on Medium]]></title>
        <description><![CDATA[Stories by Minimalist on Medium]]></description>
        <link>https://medium.com/@denlutz?source=rss-2d1e858c3016------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/proxy/1*TGH72Nnw24QL3iV9IOm4VA.png</url>
            <title>Stories by Minimalist on Medium</title>
            <link>https://medium.com/@denlutz?source=rss-2d1e858c3016------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 02 Dec 2026 07:40:29 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@denlutz/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[SAP Commerce ( Hybris ) Integration Tests without platform restart and for free]]></title>
            <link>https://medium.com/@denlutz/sap-commerce-hybris-integration-tests-without-platform-restart-and-for-free-83471d069650?source=rss-2d1e858c3016------2</link>
            <guid isPermaLink="false">https://medium.com/p/83471d069650</guid>
            <category><![CDATA[sap-commerce]]></category>
            <category><![CDATA[testing]]></category>
            <category><![CDATA[tdd]]></category>
            <category><![CDATA[hybris]]></category>
            <dc:creator><![CDATA[Minimalist]]></dc:creator>
            <pubDate>Mon, 08 Jul 2019 09:59:20 GMT</pubDate>
            <atom:updated>2019-07-08T19:45:17.087Z</atom:updated>
            <content:encoded><![CDATA[<h3>SAP Commerce ( Hybris ) integration tests without platform restart and for free</h3><p>One of the most effective things you can do in your SAP Commerce project is to build up a profound integration tests suite. I want to emphasise that by integration tests, I specifically mean the tests extending from <em>ServiceLayerTransactionalTest</em> and hitting your full spring config as well as the junit tenant database. Doing it the right way is a separate topic.</p><p>I am not a fan of massively mocked unit tests and specifically not in a hybris environment. I have many reasons for that and will discuss it in a separate post.</p><p>Back to the topic, yes you heard that right, you can compile and rerun your integration tests <strong>without</strong> restarting the SAP Commerce platform. This works with two things combined.</p><ol><li><a href="https://blogs.sap.com/2018/11/01/hotswap-with-hybris-a-free-open-source-alternative-to-jrebel/">HotSwap with Hybris</a> ( Kudos to <a href="https://people.sap.com/suleman.mohd"><strong>Suleman Mohd</strong></a><strong> </strong>) (a new free solution)</li><li>Using the <a href="https://help.sap.com/viewer/d0224eca81e249cb821f2cdf45a82ace/6.5.0.0/en-US/8bec615d86691014887ca1b28c882bef.html">Testweb Front End</a>, that is reachable via <a href="http://yourhybrisbasedomain:port/test">http://yourhybrisbasedomain:port/test</a></li></ol><p>Thats it!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*3rM_iXKxeCI2nz6j" /><figcaption>Photo by <a href="https://unsplash.com/@spacex?utm_source=medium&amp;utm_medium=referral">SpaceX</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>Your code change cycles will go down tremendously.</p><p>Some hints for the implementation.</p><ul><li>First of all use the given <a href="https://blogs.sap.com/2018/11/01/hotswap-with-hybris-a-free-open-source-alternative-to-jrebel/">blogpost from Suleman</a> to setup your hotswap reload</li><li>start the hybris server in the debug mode: ./hybrisserver debug</li><li>open the Testweb Front End, filter for your test and press the <strong>“run” button at the bottom, don’t confuse it with the one at the top of the screen</strong></li><li>verify your tests are green, now you can start developing, after each change only execute “ant build” in the extension with the actual code change</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=83471d069650" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Steps to radically speed up your react.js projects (series)]]></title>
            <link>https://medium.com/@denlutz/steps-to-radically-speed-up-your-react-js-projects-series-76d82dc3c233?source=rss-2d1e858c3016------2</link>
            <guid isPermaLink="false">https://medium.com/p/76d82dc3c233</guid>
            <category><![CDATA[react]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[redux]]></category>
            <category><![CDATA[best-practices]]></category>
            <category><![CDATA[software-development]]></category>
            <dc:creator><![CDATA[Minimalist]]></dc:creator>
            <pubDate>Mon, 24 Jun 2019 14:24:01 GMT</pubDate>
            <atom:updated>2019-06-25T11:00:41.754Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*2Awux-oqNUeEDB-y" /><figcaption>Photo by <a href="https://unsplash.com/@cakirchoff?utm_source=medium&amp;utm_medium=referral">Chad Kirchoff</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><h3>8 steps to radically speed up your react projects ( article series )</h3><p>In the following series of articles I want to tell about my experience and the best practices I discovered and/or introduced in react.js projects.</p><p>Everything I will present is based on at least 3 mid size completed projects. Its bullet proof by countless code reviews and on boarding of many colleagues, who were productive in the code base right away.</p><h4><a href="https://medium.com/@denlutz/introduce-an-opinionated-react-front-end-architecture-89bc8b67019">Introduce an opinionated react.js front end architecture</a> ✅</h4><ul><li>react.js is just a view in classical MVC</li><li>redux introduces some architecture but its incomplete</li><li>why we need to become opinionated</li><li>suggested solution for a react-redux architecture</li></ul><h4><a href="https://medium.com/@denlutz/local-first-entwicklung-im-frontend-7acddebb01bb">Enforce Local First Development (German only)</a> ✅</h4><ul><li>what is local first</li><li>why local first? ( scenarios for local first )</li><li>back end tools</li><li>front end tools</li></ul><h4>Use a rest-middleware for external communication (coming soon)</h4><ul><li>the biggest complexity pain point</li><li>present solutions thunk and saga</li><li>suggested solution</li></ul><h4>Use service object pattern for general logic (coming soon)</h4><ul><li>the service object pattern</li><li>identify unassigned logic groups</li></ul><h4>Test with common sense, not based on theory (coming soon)</h4><ul><li>common testing pitfalls in the front end</li><li>understanding test complexity and its rewards</li><li>white box vs black box</li><li>functional mocks, the source of all evil</li><li>what functional mocks are doing to your test code</li><li>state vs behaviour assertion</li><li>its all about unit size</li><li>top down test unit size discovery</li></ul><h4>Extract code with caution (coming soon)</h4><ul><li>single responsibility review with common sense</li><li>file size is no criteria for complexity</li><li>when is something complex?</li><li>fragile nature of JS apis</li></ul><h4>Use the ducks redux pattern (coming soon)</h4><ul><li>based on extract code with caution</li><li>based on unit size discovery</li><li>sample projects</li></ul><h4>Internalise domain specific languages (coming soon)</h4><ul><li>why is thinking in dsls important?</li><li>an underestimated and unknown topic in software engineering</li><li>how react fits into the picture of dsl focused development</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=76d82dc3c233" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Introduce an opinionated react front end architecture]]></title>
            <link>https://medium.com/@denlutz/introduce-an-opinionated-react-front-end-architecture-89bc8b67019?source=rss-2d1e858c3016------2</link>
            <guid isPermaLink="false">https://medium.com/p/89bc8b67019</guid>
            <category><![CDATA[react]]></category>
            <category><![CDATA[redux]]></category>
            <category><![CDATA[architecture]]></category>
            <category><![CDATA[redux-saga]]></category>
            <category><![CDATA[redux-thunk]]></category>
            <dc:creator><![CDATA[Minimalist]]></dc:creator>
            <pubDate>Mon, 24 Jun 2019 13:51:37 GMT</pubDate>
            <atom:updated>2023-04-18T14:39:41.911Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*kMi7aoqv0_FoVtSK" /><figcaption>Photo by <a href="https://unsplash.com/@litburon?utm_source=medium&amp;utm_medium=referral">laura buron</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><h4>Abstract</h4><h3>UPDATE Jan, 2023 you can find the newest version of this article on my web site: <a href="http://denislutz.com/domain-architecture-for-react">http://denislutz.com/domain-architecture-for-react</a></h3><p>The concepts described here are still correct, but little outdated…</p><ul><li>react.js is just a view (+ some controller logic) in classical MVC</li><li>redux introduces some architecture but its incomplete</li><li>why we need to become opinionated</li><li>suggested solution for a react-redux architecture</li><li>advantages of using a completely defined architecture</li></ul><h4>React is a library, not a framework</h4><p>Its known react is just a library. If we would map it to the most known design pattern MVC then it would be the V(iew) + some ability to trigger controller actions, who can exist on the view itself.</p><p>If we add redux to the stack we usually follow the official <a href="https://facebook.github.io/flux/docs/in-depth-overview.html">flux architecture</a>.</p><p>So framework wise we cover the MVC functionality and unfortunately this is still not the complete picture. To make an example this are the parts of the logic that are not mentioned in the flux architecture. The structure for the rest of logic is open for the team to decide.</p><ul><li>logging logic with addition reporting to some external bug tracking tool</li><li>domain specific logic, like some tax calculations or business objects management that is used from several react components</li><li>environment management, specifically activating some feature in dependency of the environment at runtime or feature toggles</li><li>technically neutral http and REST logic</li><li>i18n logic used by many components</li><li>mock data generation and management from central place, used by many unit and integration tests</li><li>redux store setup, specifically in dependency of the current environment</li></ul><p>So we see there are many areas left out of the flux architecture, since its goal is to organise the react view part itself and not more.</p><p>In case its left undefined where all the other logic parts go, developers will randomly make their architectural decisions. In the most cases it will result in an uncoordinated architecture, not centrally handled concerns and many specific assumptions.</p><p>So what is the solution? Obviously to cover the rest of the stack and to answer the questions, that seem unclear.</p><p>After I started working with the javascript, this issue was one of the first big problems in my eyes. Coming from the java back end development, I would say that any undefined logic group should go into a specific module. In general the <a href="https://crushlovely.com/journal/7-patterns-to-refactor-javascript-applications-service-objects">service object pattern</a> fits, that seems to be known to some people. In the same way many spring applications structure their logic.</p><p>So I integrated the following react-redux architecture that is based on best practices from a spring back end.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QxEHffvp9OnD4nyjqy-yUA.png" /><figcaption>Extended flux architecture</figcaption></figure><h4>Core new points of this architecture</h4><ul><li>we have a services layer, that is used top down from the react components, I will describe a service in a separate article in more detail</li><li>it is strictly forbidden to break the architectural borders, like passing around the reference of the <em>dispatch</em> function from redux to other architecture layers</li><li>we have a rest calls middleware that works with specific rest actions, I will present it in a separate article as part of this series.</li><li>there is no redux thunk or saga, we use a redux middleware to make async calls in only ONE place</li><li>something that I called “the action chains” and “service actions” are used as a pattern, I will describe it with the middleware</li></ul><h3>The result</h3><ul><li>with this extended architecture we can clearly assign new types of logic to the services layer. We cover the client site to the end and developers have a clear framework to structure the code</li><li>within a company you can rely that any project is following the same structure, so people have an easier way to jump in and find their way around</li><li>there are no unknown or single person specific patterns used in the stack</li><li>junior developers can focus on parts of the present parts of the architecture, without having to know everything right away</li></ul><p>I used this stack in two projects right away and made the best experience with it. During this time I brought at least 4 new developers on board into this projects. My colleagues we productive after 1–2 days inside the code base. Besides a react router integration we had no other architectural choices to make.</p><p>The core simplification comes clearly form the rest middleware and the services layer, wich I will present in the following articles.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=89bc8b67019" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Impressions after being a TDD fan]]></title>
            <link>https://medium.com/@denlutz/impressions-after-being-a-tdd-fan-efa03b67e03a?source=rss-2d1e858c3016------2</link>
            <guid isPermaLink="false">https://medium.com/p/efa03b67e03a</guid>
            <category><![CDATA[previous]]></category>
            <category><![CDATA[basics]]></category>
            <category><![CDATA[tdd]]></category>
            <category><![CDATA[presentations]]></category>
            <category><![CDATA[software-development]]></category>
            <dc:creator><![CDATA[Minimalist]]></dc:creator>
            <pubDate>Mon, 24 Jun 2019 10:13:09 GMT</pubDate>
            <atom:updated>2019-06-24T10:13:09.844Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*K2pAk4uB_0DNEFi2" /><figcaption>Photo by <a href="https://unsplash.com/@tlisbin?utm_source=medium&amp;utm_medium=referral">Tommy Lisbin</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p><strong>Back in 2008 I wrote about my first experiences with TDD after some years of practical use.</strong> I repost this article here, since it is discussing the very important basics of TDD.</p><p>For around 3 years ago I came over the TDD approach and got very excited by it. It seemed very logical in lots of situations to me. I was doing once a presentation about it and want to discuss in this blog post what I have learned after 3 years applying it where ever I could.</p><p>First of all, here is the presentation summarising the theory and the procedure itself.</p><p><a href="https://www.scribd.com/presentation/57739892/Test-Driven-Development">https://www.scribd.com/presentation/57739892/Test-Driven-Development</a></p><p>If you would ask me today if all the theory I read in the books and presented applies, I would answer, yes… in the most cases. Maybe the most important thing to keep in mind is the <a href="http://en.wikipedia.org/wiki/Return_on_Investment">Return Of Investment (ROI)</a> and this is how the most project managers and architects want to see it which is logical.</p><p>What got me interested the most in the first place is the following principle included in TDD.<br> Lets look at the traditional waterfall model first:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/568/0*0VsTi5nB78KLenbS.png" /></figure><p>Important here is to mention, that for a developer this is not only the way how the project process mostly works, even in an agile sprint cycle. It is the workflow he goes through writing any small feature. An example here would be a service method a developer would have to write in a spring architecture, that is consuming injected DAO Instances.<br> TDD comes and suggests a development workflow in the following way:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/532/0*MI8ycmhMn1dpNX4q.png" /></figure><p>Notice the position of “What?” and “How?” in this case.</p><p>What is so special in this workflow change and what did inspire me here so much?</p><p>Well two things…</p><h4>Design only if needed</h4><p>Not in a huge procedure upfront not knowing if it will work or not.<br>Sit down with a junior developer and analyse how he approaches a problem he has to solve. One path he could take is sitting down and trying to draft his stack of methods on a piece of paper and we know the UML approaches we have been though at school. This is actually the typical classical view of a task for an architect, that never worked in the reality.</p><p>The other way is to start implementing using TDD and designing your methods stack along the way.</p><p>Yes we need the big architectural design on the level of system APIs, your REST communications to other systems. But on the code level its hard to see your design upfront and its not necessary to do it. This is the basic though of agile development how I learned it from Martin Fowler.</p><p>As <a href="http://martinfowler.com/articles/newMethodology.html">Martin Fowler describes in this article</a>, the waterfall procedure is predictive and therefore completely hard to execute, since we want to predict things and grasp a huge system that is very hard to grasp.</p><p>The agile process is adaptive. Meaning that we go driven by the features we have and design along the way, adapting it to our requirements, asserting the functionality through the test. This is the reason why no agile procedure can be done without the test.<br>Does your manager knows it? Ask him how he defines agile? Besides doing your requirements in short loops of two weeks.</p><h4>Test = Specification</h4><p>This is the rule lots of people who don’t like TDD don’t understand.<br> You ask them what does TDD means for you?</p><p>“Oh well this is the approach where you just write the test first… total nonsense for me, how should I know what my code will look like upfront…”</p><p>Yes it is nonsense if you do exactly the same what you do in the classical “test at the end” approach.</p><p>As I looked at the fact “ test = spec “, the main thought coming into my mind is that “test” in general, is the wrong word to use, once we are using TDD. We don’t have a test anymore since a test is something that you apply to some product you have already produced.</p><p>What we are talking about here is an “automatically executable specification” of our code. This is the most important point to understand and all other principles follow after it:</p><ul><li>Having written the test as the specification</li><li>Focusing on one specific part of your system at a time</li><li>Holding one part of your code in your mind while writing the test for it, it goes along with something that I call “do it properly while you know it, then you will forget it”, what is easier to write your test as you write the code or some weeks later once you forgot it?</li></ul><p>Now to the other part of this discussion.</p><p>Is TDD valuable to us and should we use it ?</p><p>While the most employers want you to apply it, at least as you see it in the job postings, there are still folks out there that you need to convince to do it and I see them again and again. Thats why I want to discuss it here again.</p><p>There is a reasons why not any developer is adopting TDD. I have been experiencing the following yet:</p><h4>Developers just don’t understand TDD</h4><p>They are not passionate about it. They do some mix of TDD and Waterfall Testing without clearly using the advantages of TDD.</p><p>The solution here is to clearly experiment with some samples and try to apply the principles. Go though my presentation at the beginning of the post. You can work though 3 cycles in TDD, apply the Eclipse short keys for your code generation and try to understand what is each step bringing to you in value while programming.</p><h4>Test setup is time consuming</h4><p>This is the biggest enemy of TDD and I my self was trapped in it several times.<br> What you have here is mostly a very complicated business domain combined with a tedious fixtures setup.</p><p>The reason for it is usually a bad technology choice and a wrongly given fixtures environment.<br> The technical lead of the project should care about the degree and the time investment for a test setup. If needed, a dedicated person should be assigned the task to create an easy test setup for any developer and a good base for your tests.</p><p>Here are my critical questions to ask and solutions coming along with them:</p><p>a) Do you have textual DSL fixtures? Like XML, CSV or YAML (Rails)?</p><p>Well, don’t expect your team to reach a good test coverage then, you have lost it for a big part. Yes a good developer can survive with restricted testing and I worked with developers like that. As you know though any code and any coding procedure gets complicated soon enough, your goal is to make it as simple and as productive as possible and this is your competitive advantage.</p><p>Back to fixtures…. A huge improvement usually comes by setting up an API to create fixtures and this is what helped me extremely in several projects to reach a good test coverage.</p><p>You can see movements in the java and rails community that prove it big time:</p><ul><li>Java’s <a href="http://en.wikipedia.org/wiki/Plain_Old_Java_Object">POJOs term</a>, objects you can create easily in any testing environment</li><li>Ruby’s libraries like <a href="https://github.com/thoughtbot/factory_girl/wiki">factory girl</a> , an API to create your objects for the test</li></ul><p>And by the way, by creating your objects programmatically and not with fixtures you strongly force the developers to simplify the object creation. You create two clients of your code immediately. The test and the code you will use your objects in.</p><p>b) Besides the fixtures, is a general test setup easy? Do you need a bunch of knowledge to setup a test?</p><p>The last thing I want to discuss is the ROI. This principle applies in any testing environment, doesn’t matter if its easy to setup your test or not. It should be your first priority rule to decide about going with TDD in a certain situation or without it. Potentially you can motivate any new method of your code with a test, to follow strongly the TDD principle but its not always the best thing to do.<br> What you should go for, is obviously highest ROI. Basically reaching the most value out of your test by investing the lowest amount of time.</p><p>For my self I experienced that something that I call “basic code execution” as a test and some basic assertion bring already a huge value with them. This is how I perceived the profit of TDD just by applying this rule.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/423/0*TVs9MveQ6dh5l0TE.png" /></figure><p>Have you ever heard the saying “Better some test than no test at all!”, this goes along with this experience and it is absolutely true. I would say you reach definitely over 50% of possible profit out of tests by just having the code execution.</p><p>What does a basic code execution bring you?</p><ul><li>Testing bean configurations in a spring framework architecture.</li><li>Indirectly testing your code areas serving your new feature.</li><li>Designing your APIs how you want them to be up front.</li><li>Focusing on one part of code instead of starting a debugging session in a method stack.</li><li>Testing a controller in a Rails environment renders and tests the belonging view with it.</li></ul><p>So apply the minimum amount of work and get already a huge value from it.</p><p>These are my general thoughts on TDD after using it for some time. I would say its still a great concept, I love to apply it and can only recommend it to all the others.</p><p>My question to others would be:</p><p>If you know TDD but don’t apply it, what is your reason for it?<br> What is the highest possible test coverage you have ever reached in a real project?</p><p><em>Originally published at </em><a href="http://denislutz.com/3-years-beeing-a-tdd-fan"><em>http://denislutz.com</em></a><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=efa03b67e03a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[JRuby in Java Projects]]></title>
            <link>https://medium.com/@denlutz/jruby-in-java-projects-ef4fb69a4927?source=rss-2d1e858c3016------2</link>
            <guid isPermaLink="false">https://medium.com/p/ef4fb69a4927</guid>
            <category><![CDATA[jruby]]></category>
            <category><![CDATA[ruby]]></category>
            <category><![CDATA[polyglot-programming]]></category>
            <category><![CDATA[java]]></category>
            <dc:creator><![CDATA[Minimalist]]></dc:creator>
            <pubDate>Mon, 24 Jun 2019 09:56:50 GMT</pubDate>
            <atom:updated>2019-06-24T14:29:02.598Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*OyHYneCLRYhuq7Lm" /><figcaption>Photo by <a href="https://unsplash.com/@cieloadentro?utm_source=medium&amp;utm_medium=referral">Roksolana Zasiadko</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>Back in 2011 I gave a talk about JRuby at <a href="http://www.namics.com/">Namics</a>.</p><p>Topic: JRuby in Java Projects.</p><p>My goals have been:</p><ul><li>focusing on several project areas, where you can use jruby successfully</li><li>share the experience that I made using ruby in the last years</li><li>prooving that things can be done easier as they are done in typical java projects</li></ul><p><a href="https://www.scribd.com/presentation/57653412/JRuby-in-Java-Projects#from_embed">JRuby in Java Projects</a></p><p><em>Originally published at </em><a href="http://denislutz.com/jruby-in-java-projects/"><em>http://denislutz.com</em></a><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ef4fb69a4927" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Local First Entwicklung im Frontend]]></title>
            <link>https://medium.com/@denlutz/local-first-entwicklung-im-frontend-7acddebb01bb?source=rss-2d1e858c3016------2</link>
            <guid isPermaLink="false">https://medium.com/p/7acddebb01bb</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[tdd]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[german]]></category>
            <dc:creator><![CDATA[Minimalist]]></dc:creator>
            <pubDate>Mon, 24 Jun 2019 06:39:04 GMT</pubDate>
            <atom:updated>2019-06-24T12:03:27.135Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*O77xShQeSZlyV_PG" /><figcaption>Photo by <a href="https://unsplash.com/@priscilladupreez?utm_source=medium&amp;utm_medium=referral">Priscilla Du Preez</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><h3>Einleitung</h3><p>Gewöhnliche Front-End-Anwendungen müssen fast immer Daten von anderen Datenlieferanten konsumieren, meistens von einem Backend-System. Oft sind jedoch die Backends schwer-gewichtig, stehen nicht sofort zur Verfügung oder können generell nicht von der lokalen Entwickler-Umgebung angesprochen werden.</p><p>An dieser Stelle hat sich in meiner Entwicklungspraxis das Konzept der „local first“, auf Deutsch, der „lokal-zuerst“-Entwicklung sehr bewährt.</p><p>Was ist “local first” ?</p><p>Unter „lokal-zuerst“, versteht man die Arbeitsweise, bei der bereits auf der lokalen Maschine alles so nachstellt wird, wie es auch auf anderen Umgebungen vorgeplant wurde. Vor allem das Backend-System wird daher immer als ein lokaler HTTP-Server aufgesetzt, welches mit genau der selben REST-Definition funktioniert.</p><h3>Motivation</h3><p>Wenn man sich nun fragt, wozu derartiges Vorgehen nötig ist oder der Mehrwert generell fraglich erscheint, möchte ich folgende kritische Projekt-Situationen als Indikatoren kurz benennen:</p><ul><li>Du musst bereits auf deinem Rechner gegen eine lokale Backend-Umgebung integrieren, dessen Build länger als 10 Sekunden oder gar über eine Minute dauert, dabei sind eigentlich nur Änderungen im Front-End notwendig.</li><li>Du musst ständig auf DEV- oder andere Umgebungen ausrollen, um die Integrität mit der REST-API zu prüfen.</li><li>Dein Javascript-Code muss einen komplizierten Token-Refresh-Workflow implementieren, den du nur manuell, durch HTTP Request-Manipulation im Debugger und nur auf externer Umgebung nachstellen kannst.</li><li>Deine Backend-API befindet sich parallel in Entwicklung, es ist unklar ob diese zeitlich fertig wird.</li><li>Du erwartest Freischaltungen von anderen Unternehmensabteilungen, bis die API verfügbar wird.</li><li>Du musst lokal ein Backend lange aufsetzen, diesen täglich updaten oder sogar deine Backend-Kollegen um Hilfe fragen, damit dein Frontend überhaupt dagegen entwickelt werden kann.</li><li>Obwohl das <a href="https://storybook.js.org/">Storybook Framework</a> eingesetzt wird und Komponenten teilweise gerendert werden, gibt es keinen Weg um die Gesamtanwendung schnell auszuführen</li></ul><p>Wenn du beschriebe Szenarien in deinem Projekt ähnlich vorfindest, dann ist die lokal-zuerst Entwicklung höchst empfehlenswert.</p><p>Bezug zur Kontinuierlicher Integration (CI)</p><p>Mit lokal-zuerst erfüllt man eigentlich zwei der Grundpfeiler der Continious Integration, die bei den klassischen Quellen, wie z.B. <a href="https://www.martinfowler.com/articles/continuousIntegration.html">Martin Fowler, definiert wurden</a>.</p><ol><li>Teste in einer Kopie von deiner Produktionsumgebung: dies erreicht man , durch eine Nachstellung der externen REST-API auf der lokalen Umgebung.</li><li>Halte den Build kurzläufig: mit einer schnell integrierbaren Kopie der externen Umgebung, reduziert sich dein Build auf reine Javascript-Build-Updates.</li></ol><h3>Umsetzung</h3><p>Zur Umsetzung ist vor allem zu sagen, dass es einfacher geht als es klingt, denn gute Werkzeuge gibt es bereits, wahrscheinlich hast du schon einige auch selbst gesehen.</p><p>Zu Grunde liegt wie immer die REST-API, diese muss lokal nachgestellt werden.</p><p>Die Schnittstelle unterteilt sich in zwei grosse Bereiche:</p><ul><li>die Endpunk-Pfade mit den HTTP Verben</li><li>das Schema der Domänen-Objekte (Attribute, Ihre Typen und Beziehungen zu anderen Datensätzen ), mittels JSON-Standard definiert</li></ul><p>Glücklicherweise folgt eine gute REST-API indirekt dem Domänen-Modell selbst, so dass eigentlich die Endpunkte direkt vom Schema abgeleitet werden können und man durch JSON allein in vielen Fällen die Schnittstelle definieren kann. Somit dient JSON fast immer als genügende Kontraktgrundlage der Schnittstellen.</p><h4>Grundlegendes zu JSON</h4><p>Generell hat es sich bewährt JSON-Strukturen von vorne rein dynamisch aufzubauen.</p><p>In Javascript bedeutet es, dass man durchgehend Objektbäume definiert, welche dann in eine JSON-Datei geschrieben werden. Direkt kopiertes JSON zu nutzen scheint am Anfang zwar sehr bequem, bringt jedoch von vorne rein viele Wiederholungen in den Beispiel-Daten, vor allem jedoch, verhindert es eine dynamische Generierung von Datensätzen in naher Zukunft. Wenn du jedoch sicher weist, dass dein JSON sich kaum ändern kann es natürlich auch direkt verwendet werden.</p><p>Eins der wichtigsten Punkte, ist die „best practice“ die generierten Daten auch in den Unit-Tests zu nutzen. Somit diktiert man bewusst das Objekt-Schema von einer Stelle. Muss ein Attribut geändert werden, so passiert es wirklich zentral und erspart potentielle Fehlerquellen. Wie empfindlich Javascript an dieser Stelle ist möchte ich in folgendem Beispiel demonstrieren.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*v17t-YwLBh9lm_3uiX-AHg.png" /></figure><p>Dein trainiertes Auge sieht es bestimmt schon:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JTU1Ua6jJMF55Jxiy5N8wg.png" /></figure><p>Verschreibt man sich nur bei einem Attribut, so schleichen sich undefinierte Werte in Objekten ein. Die Lösung, ist die strikte Regel JSON Inhalte zentral auszulesen, anstatt viele Kopien einzelner Objekte oder alleinstehende Objektbäume nur in Tests anzulegen. Auch wenn es heisst ein Test sollte selbst-enthaltend sein, kann er seine Test-Daten von einer externen Quelle beziehen. Hierfür empfehle ich eine Service-Klasse zur Test-Datenverwaltung, welche dann von den Tests genutzt wird und für Datenintegrität sorgt.</p><h3>Backend-Server</h3><p>Nach der Datenverwaltung, möchte ich auf die eigentlichen Server-Lösungen eingehen, die unser Backend replizieren werden. Die Anforderung an dieser Stelle, ist es die Anwendung wie der Endbenutzer lokal auszuführen zu können, somit handelt es sich um einen manuellen End-User-Test, der am Ende der <a href="https://martinfowler.com/bliki/TestPyramid.html">Test-Pyramide</a> liegt. Wichtig ist es ausschliesslich HTTP Server zu nutzen um eben möglichst realitätsnah zu arbeiten. Die Mock-Bibliotheken wie <a href="https://github.com/nock/nock">„Nock“</a>, halte ich an dieser Stelle für unpassend, weil Sie einen anderen Test Fokus haben und leider auch durch sich selbst sofort Komplexität erzeugen.</p><h4>JSON-Server</h4><p>Das Projekt <a href="https://github.com/typicode/json-server">JSON-Server</a> ist der erste bewährte Kandidat eines lokalen HTTP-Servers. Dieser benötigt nur JSON-Dateien um schnell einen vollen REST-Service nachzubilden.</p><p>Installation nach <a href="https://github.com/typicode/json-server#getting-started">offizieller Dokumentation</a>.</p><pre>npm install -g json-server</pre><p>Man generiere zuvor folgende JSON Struktur, welche in der Datei mit dem Namen db.json abgelegt wird. Hierzu ist die Methode <a href="https://developer.mozilla.org/de/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify">JSON.stringify()</a> sehr passend.</p><pre>{&quot;posts&quot;: [<br>    { &quot;id&quot;: 1, &quot;title&quot;: &quot;json-server&quot;, &quot;author&quot;: &quot;typicode&quot; }<br>],<br> &quot;comments&quot;: [<br>   { &quot;id&quot;: 1, &quot;body&quot;: &quot;some comment&quot;, &quot;postId&quot;: 1 }<br>]}</pre><p>Sonst brauchen wir noch ein Start-Script, der wie folgt aussieht (gleich in package.json definieren)</p><pre>json-server --watch db.json</pre><p>Und schon kann die erste Response aufrufen werden:</p><p><a href="http://localhost:3000/posts/1">http://localhost:3000/posts/1</a></p><p>Wie man sieht, folgt die erste Route selbst der JSON-Struktur, dementsprechend muss man eigentlich nichts mehr anpassen, vorausgesetzt die REST-API folgt gewöhnlichen Konventionen.</p><p>Nun stell dir vor, du kriegst eine Beispiel-Response vom Backend und kannst nach wenigen Minuten dagegen lokal entwickeln, sogar vollständige <a href="https://de.wikipedia.org/wiki/CRUD">CRUD</a> Operationen sind möglich. Dazu sagt die <a href="https://github.com/typicode/json-server">Dokumentation</a> von JSON-Server:</p><p>„<em>If you make POST, PUT, PATCH or DELETE requests, changes will be automatically and safely saved to </em><em>db.json using </em><a href="https://github.com/typicode/lowdb"><em>lowdb</em></a><em>.“</em></p><p>Neben dem Basis-Setup und als ein Freund der <a href="https://de.wikipedia.org/wiki/Paretoprinzip">80-zu-20-Regel</a>, würde ich noch folgende Sachen als notwendiges Wissen festlegen.</p><p>Eine Id bei jedem JSON-Objekt ist potentiell erforderlich: Dies erfordert der JSON Server selbst, damit die Entität-Modifikationen gemacht werden können. Am Anfang sieht man öfters diese Aufforderung, wenn man z.B. ein JSON-Objekt löschen möchte. Ist ein „Id“-Attribut auf der betroffenen Entität gar nicht geplant, so ist es jedem selbst überlassen diesen eventuell an dieser Stelle einzuführen. Damit bequem gearbeitet werden kann.</p><p>Port Configuration:</p><pre>json-server --watch db.json –port 3004</pre><p>Extra Routen:</p><pre>json-server --watch db.json –port 3004 --routes routes.json</pre><p>Der Inhalt von routes.json definiert dann deine Routen.</p><p>Hier definieren wir die Routen, die dein Frontend lokal absetzen kann. Jede Route wird dann auf die JSON-Server-Routen umgeleitet. Bequem sind vor allem die Platzhalter für dynamische Routenabschnitte, hier :id oder die Query-Parameter.</p><h4>Middlewares</h4><p>Auch eine Middleware kann angehängt werden, mit der du dann sehr viel Kontrolle über deine HTTP-Requests gewinnst. Mehr dazu findet man <a href="https://github.com/typicode/json-server#add-middlewares">hier</a>.</p><p>Mehr ist es nicht, aus meiner Erfahrung kannst du bereits mit diesem Setup diverse Oberflächen für gängige Microservices entwickeln.</p><h4>Express.js</h4><p>Ist am Anfang klar, dass es ein grosses Projekt wird, man viele HTTP-Abläufe lokal nachstellen möchte, volle Kontrolle über Routing und Middleware braucht, so steht einem vollständigem <a href="https://expressjs.com/de/">Express.js als Server</a> nichts im Weg. Dieser ist etwas grösser beim Aufsetzen, danach jedoch erfüllt es alle notwendigen Anforderungen und hat vollständige Funktionalität eines REST-Servers.</p><p>Hier gelten dieselben Prinzipien wie bei dem JSON-Server. Weil Express.js bekanntes Framework bereits ist, verweise ich hier nur auf <a href="https://expressjs.com/de/starter/hello-world.html">Dokumentation</a>.</p><h3>Frontend einbinden</h3><h4>Der Standard: Storybook</h4><p>Ist unser Backend bereit, so müssen wir auch das Frontend selbst lokal ausführen. Der verbreitete Standard an dieser Stelle ist sicherlich das <a href="https://github.com/storybooks/storybook">Storybook</a>. Dieser ist meiner Meinung nach fast immer empfehlenswert. Sogar wenn man eine Single Page Application bauen muss, ermöglicht es Navigationspfade und Komponenten-Zustände zu definieren, ohne zu diesen immer wieder bei der Entwicklung navigieren zu müssen. Unschlagbar ist Storybook bei der Entwicklung von Komponenten-Bibliotheken, in Kombination mit dem <a href="https://github.com/storybooks/storybook/tree/next/addons/knobs">Knobs-Plugin</a> macht es ein Interaktives entwicklen mit sehr vielen Properties möglich.</p><h4>Webpack-Dev-Server</h4><p>Als das Standard Werkzeug zum Bündeln von Artifakten, bietet auch Webpack einen lokalen Server zur Entwicklung.</p><h4>Simple HTTP Server</h4><p>Natürlich kann ein beliebiger HTTP Server ebenfalls das Frontend lokal einbinden, mein eigener Favorit ist <a href="https://www.npmjs.com/package/http-server">http-server</a>. Dieser lässt sich sehr leicht installieren und starten.</p><h3>Umgebungen definieren</h3><p>Ein letzter Punkt den ich erwähnen möchte, ist die Praxis, die Laufzeit-Umgebungen von vorne rein klar zu definieren, dabei kann es bereits lokal, mehr als eine sein.</p><p>Es können dann beispielsweise folgende Umgebungen existieren.</p><ul><li>TEST — diese wird ausschließlich für Unit-Tests genutzt, hierbei leiten sich bestimmte URL und Konstanten wie der eingesetzte Benutzer oder sein Auth-Schlüssel ab.</li><li>LOCAL-DEV — diese Umgebung geht direkt von dem Entwickler-Rechner gegen eine externe DEV-Umgebung somit variieren alle URLs und Konstanten</li><li>DEV, INT und PRD sind dann gewöhnliche Umgebungen die man aus anderen Projekten kennt, die sensitiven Konstanten hierfür werden dann auf der jeweiligen Umgebung separat eingebunden.</li></ul><p>Ein gutes Werkzeug für diesen Setup ist das Projekt <a href="https://github.com/mozilla/node-convict">„Convict“</a>. Dieser deckt die typischen Anforderungen nach den besten Methoden ab.</p><h4>Überblick</h4><p>Zusammenfassend entsteht in etwa die folgende Struktur bezüglich Umgebungen, JSON-Definition und API-Beziehungen. Bitte hier beachten dass es sich hierbei nur um eine abstrakte Skizze und kein valides UML handelt.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Gw3fUNZCveTrZ6iiowOwoQ.png" /></figure><h3>Fazit</h3><p>Betrachtet man lokal-zuerst, so bietet es trotz des einfachen Prinzips einige Vorteile. Aus meiner Erfahrung war ich oft froh, den lokalen Setup einfach bei mir zu haben und betrachte es als die „Geheimwaffe“ eines vorausschauenden Entwicklers.</p><p>Speziell bei einem Team mit vielen Junior-Entwicklern oder auch grossen Teams, ist die lokal-zuerst Entwicklung als feste Projekt-Vorgabe empfehlenswert, weil es oft schnell aus dem Bild gerät, wie viel Entwicklungszeit auf Integrations-Vorgänge verbraucht wird und man ganze Projekte damit verlangsamen kann.</p><p>Mit den vorgestellten Werkzeugen, kann man auch nicht mehr sagen, dass dieses Prinzip einen grossen Aufwand erfordert, weder initial noch im weiteren Projektverlauf.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7acddebb01bb" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>