<?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 Daniel Ochoa on Medium]]></title>
        <description><![CDATA[Stories by Daniel Ochoa on Medium]]></description>
        <link>https://medium.com/@gameboy45?source=rss-f5f2ae2e19f7------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*pAD36dnyvcCellRvv03tqQ.png</url>
            <title>Stories by Daniel Ochoa on Medium</title>
            <link>https://medium.com/@gameboy45?source=rss-f5f2ae2e19f7------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 21 Nov 2026 19:22:08 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@gameboy45/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[The Multi-LLM Self-Improving Planning Loop]]></title>
            <link>https://levelup.gitconnected.com/the-multi-llm-self-improving-planning-loop-545327cf00a9?source=rss-f5f2ae2e19f7------2</link>
            <guid isPermaLink="false">https://medium.com/p/545327cf00a9</guid>
            <category><![CDATA[llm]]></category>
            <category><![CDATA[ai]]></category>
            <category><![CDATA[startup]]></category>
            <dc:creator><![CDATA[Daniel Ochoa]]></dc:creator>
            <pubDate>Mon, 09 Feb 2026 22:26:15 GMT</pubDate>
            <atom:updated>2026-02-09T22:26:15.174Z</atom:updated>
            <content:encoded><![CDATA[<p><strong>How to turn model disagreements into stronger plans that get smarter over time</strong></p><p>If you’ve ever watched an AI model confidently propose a plan and thought “this sounds great, but I don’t trust it,” you’re not alone. Single-model planning is useful for speed, but it amplifies whatever bias that model carries. One model over-engineers. Another hand-waves risk. Another gets practical but misses strategy. Another is great at poking holes but weak at putting things together. This applies whether you’re planning a product, writing a document, building a go-to-market strategy, or drafting a proposal.</p><p>A simple way to fix this: have two models plan together. One drafts, the other stress-tests it, and they go back and forth until the plan stops changing in meaningful ways. You don’t need a perfect pairing. Pick two models that behave differently and run the loop. The differences are the point. They surface blind spots fast.</p><p>This isn’t “asking two models the same question.” It’s a structured loop that uses disagreement as signal and systematically reduces the gaps that either model would leave on its own.</p><h4>What It Is</h4><p>At its simplest, the loop looks like this:</p><ol><li>Draft something with one model (a spec, a document, a strategy, a proposal)</li><li>1. Critique it with a second model</li><li>1. Revise and repeat until they converge</li><li>1. Ship the final version plus a change log</li></ol><p>Think of it like a design review where the reviewer is a different language model with different strengths and blind spots. You don’t need to assign formal roles or set up anything complicated. You just need two models and the patience to let them argue it out.</p><h4>Why It Works</h4><p><strong>It converts confidence into evidence</strong></p><p>Models are excellent at sounding certain. The loop forces each claim to face questions like: What could go wrong here? What’s this going to cost to maintain? How would you actually measure success? What’s the smallest version that proves this idea works?</p><p>When a model has to defend a point under critique, weak reasoning becomes obvious fast.</p><blockquote>It exploits different model biases instead of suffering from them</blockquote><p>Different models are predictably strong in different ways. One might be great at big-picture thinking. Another might be sharper on risk and edge cases. One might write better success criteria. Another might be more aggressive about cutting scope.</p><p>The loop turns those differences into coverage.</p><blockquote>It produces plans you can actually build from</blockquote><p>A single model can produce a plan that *feels* complete. The loop produces a plan that can survive contact with reality: real costs, real timelines, real customer behavior.</p><p>The output is less about being clever and more about being defensible.</p><blockquote>It’s faster than doing it yourself</blockquote><p>You still matter for final judgment, but models can do the heavy lifting of generating alternatives, spotting risks, rewriting weak sections, and producing a list of what changed. The loop compresses multiple rounds of review into one session, and you only step in for the final calls.</p><h4>Two Models, One Loop</h4><p>You don’t need a complex multi-agent setup. The loop works with two models trading a plan back and forth. One drafts, the other critiques, and you run a couple rounds until the plan stabilizes.</p><p>One thing I learned fast: the drafting model needs permission to change its mind. If you just say “write a plan,” it gets stubborn when challenged. If you frame it as “your job is to make this plan better for the user,” it tends to accept good critiques and move on. That small framing shift keeps the loop productive instead of adversarial.</p><p>You don’t need to know each model’s strengths in advance. The loop surfaces them. When Model B catches something Model A missed, the plan gets better, and Model A incorporates the fix because it’s oriented toward the best outcome, not toward being right.</p><h4>What It Looks Like in Practice</h4><p>A good plan isn’t the one with the most detail. It’s the one that makes the fewest expensive mistakes later.</p><p>Here are common weaknesses and how the loop catches them:</p><p><strong>The plan that sounds done but isn’t. </strong>You ask a model to plan a product launch. It gives you a clean timeline with milestones, messaging, and channel strategy. Looks great. The second model asks: “Who owns each milestone? What happens if the beta delays by two weeks? Where’s the fallback if paid ads underperform?” Suddenly the plan has gaps you wouldn’t have caught until launch week.</p><p><strong>The strategy that ignores trade-offs. </strong>A model drafts a pricing strategy and confidently recommends freemium. The second model points out that your support costs scale with free users, your conversion benchmarks assume a product category with higher switching costs, and the “upgrade path” is vague. The plan gets revised to include a usage cap, a clearer paid tier, and actual conversion targets.</p><p><strong>Scope creep disguised as ambition.</strong> The draft says MVP includes a mobile app, integrations with five platforms, an admin dashboard, and a referral program. The second model pushes back: “Which of these proves that people want the core product? Ship the one thing that answers that question first.” The scope gets cut in half and the plan gets stronger.</p><p><strong>Vague success criteria. </strong>The plan says “we’ll measure engagement and iterate.” The second model asks: “What metric? What threshold? What do you do if you hit the number but retention is flat?” The plan gets rewritten with specific targets and decision points.</p><p><strong>Either/or framing that hides a better option. </strong>Should we sell direct or go through partners? One model argues direct, the other argues partners. Through the back-and-forth, a third option emerges: start direct to learn the sales motion, then bring on partners once the playbook exists. Neither model proposed that initially. The debate created it.</p><p>That last pattern is the biggest value. The loop doesn’t just pick sides. It often finds the synthesis that keeps upside and reduces risk.</p><h4>How to Run It</h4><p>Here’s the step-by-step, including the prompts you can copy and paste.</p><p><strong>Step 1: Draft (Model A). </strong>Ask your first model to generate a complete plan. The prompt:</p><blockquote>Write a complete plan for X. Include the key phases, budget or resource needs, risks, success criteria, and the decisions that need to be made. Make claims specific and testable. Your goal is to produce the best possible plan for the user, not to defend your first draft.</blockquote><p><strong>Step 2: Critique (Model B). </strong>Paste the plan into your second model and let it tear it apart. The prompt:</p><blockquote>Critique this plan. List missing pieces, things that could go wrong, costs that are underestimated, vague claims, and where it is making assumptions without evidence. Suggest concrete fixes.</blockquote><p><strong>Step 3: Rebut and refine (Model A).</strong> Feed the critique back to the first model. The prompt:</p><blockquote>Here is the critique from another model. Your job is to produce the strongest plan for the user. Incorporate valid points, revise weak sections, and concede where the critique is right. Push back only where you have clear reasoning. Note what changed and why.</blockquote><p><strong>Step 4: Repeat until convergence.</strong> Send the revised plan back to Model B for another pass using the same critique prompt. In my experience, two to three rounds is usually enough. You’re done when the critique shifts from “this is missing something important” to “tighten the wording here, consider this small trade-off.”</p><p><strong>Step 5: Produce artifacts. </strong>Ask Model A for the final deliverables. The prompt:</p><blockquote>Produce the final plan, a change log showing how it evolved, open questions, risks and mitigations, and a clear scope line showing what’s included and what’s not.</blockquote><p>Those artifacts are what make it ready to act on.</p><p>One caveat: this loop is great for planning, but it’s not a substitute for domain experts. If the plan touches legal, security, medical, or financial decisions, treat the loop as a drafting and review tool, then validate with real expertise.</p><h4>What Makes It Work</h4><p><strong>Use disagreement as a feature. </strong>Don’t optimize for consensus. Optimize for clarity. If two models disagree, that’s often where the highest-risk decision is hiding.</p><p><strong>Force specificity. </strong>The loop breaks when feedback stays abstract. “Improve the onboarding flow” isn’t useful. “Add a progress indicator on step 2, reduce form fields from 8 to 4, and add a skip option for optional sections” is useful.</p><p><strong>Ask about the controls, not just the plan. </strong>Many plans describe what gets built and forget what keeps it running: who has permissions, how you roll back a bad change, what happens when usage spikes, how you handle abuse. Your second model should be explicitly asked to hunt for these gaps every time.</p><p><strong>Capture decisions and rationale. </strong>A plan without rationale becomes fragile. The loop naturally generates rationale. Keep it.</p><h4>Closing the Loop: Self-Learning</h4><p>The best artifact from the loop isn’t just the final plan. It’s the change log. It shows exactly what was wrong, what got fixed, and why.</p><p>After the loop converges, do one more pass. Ask each model what it missed and what it would do differently next time:</p><p><strong>Reflection Prompt (Model A):</strong></p><blockquote>Review the change log from this planning session. List the mistakes you made in your initial plan, what the critique caught, and why you missed it. Write a short set of planning principles you would follow next time.</blockquote><p><strong>Reflection Prompt (Model B):</strong></p><blockquote>Review the change log. List any critiques you raised that were correctly rejected and why they were wrong. Also list the critiques that led to the biggest improvements. Write a short set of review principles for next time.</blockquote><p>Save those lessons. Next time you run the loop, paste them in at the top as constraints. Model A gets its planning principles, Model B gets its review principles, and both start from a higher baseline.</p><p>Over time, you stop re-fighting the same battles: vague success criteria, missing risk factors, unrealistic scope. The debates shift to real trade-offs instead of basic cleanup. That’s when the loop starts to compound.</p><h4>The Payoff</h4><p>The loop produces plans that are more realistic, safer by default, and easier to execute because the ambiguities are surfaced early.</p><p>But with self-learning, the payoff goes beyond any single plan. The models stop making the same mistakes. The debates get sharper. The plans get tighter. And you end up with something rare: not just a good plan, but a planning process that improves every time you run it.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=545327cf00a9" width="1" height="1" alt=""><hr><p><a href="https://levelup.gitconnected.com/the-multi-llm-self-improving-planning-loop-545327cf00a9">The Multi-LLM Self-Improving Planning Loop</a> was originally published in <a href="https://levelup.gitconnected.com/">Level Up Coding</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How We Increased Productivity by 350% using AI]]></title>
            <link>https://medium.com/swlh/how-we-increased-productivity-by-350-using-ai-a99f5da119ae?source=rss-f5f2ae2e19f7------2</link>
            <guid isPermaLink="false">https://medium.com/p/a99f5da119ae</guid>
            <category><![CDATA[software-engineering]]></category>
            <category><![CDATA[artificial-intelligence]]></category>
            <category><![CDATA[engineering-mangement]]></category>
            <category><![CDATA[automation]]></category>
            <category><![CDATA[developer-productivity]]></category>
            <dc:creator><![CDATA[Daniel Ochoa]]></dc:creator>
            <pubDate>Sun, 21 Dec 2025 17:18:09 GMT</pubDate>
            <atom:updated>2025-12-21T17:18:09.148Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_yn9r4D0FVop11cvG6jG0A.png" /></figure><p>Yesterday, an engineer shipped a feature from initial requirements to deployed code in 2 hours. The same workflow used to take three days minimum, often stretching to a week when we factored in context switching and handoffs. We didn’t hire more engineers. We didn’t adopt faster development tools. I fundamentally rethought where our organization invested its quality effort, then built systems that made the new process reliable enough to trust.</p><p>We measure our engineering performance using Pensero, an AI-powered platform that tracks real-time productivity metrics by integrating with GitHub, Jira, and Slack. After implementing the system I built, our entire team landed in the top 10% of Pensero’s global leaderboards. This wasn’t self-reported improvement or internal metrics we could massage. This was third-party validation showing our team performing at an elite level compared to engineering organizations worldwide. The 350% productivity gain I’m describing isn’t aspirational or theoretical. It’s measured, verified, and benchmarked against the broader industry.</p><p>The breakthrough wasn’t technical. It was organizational. I discovered that our software development lifecycle was optimized for the wrong thing. We’d spent years getting better at writing code quickly, when the real bottleneck was the quality and completeness of the planning artifacts that preceded code. Requirements documents that were vague about edge cases. Implementation plans that missed architectural implications. Handoffs between product managers and engineers where context got lost and assumptions went unchallenged.</p><p>I made a bet. If I could get the organization to invest more heavily upfront in producing rock-solid requirements and implementation plans, the actual coding and deployment could become almost mechanical. But that bet only pays off if you can prove that high-quality planning artifacts reliably translate into high-quality code. I needed to build the infrastructure that would make the organizational change viable. This article explains how I did that and what it means for how your organization should think about AI productivity.</p><h3>The Problem I Was Actually Solving</h3><p>You already know how most development processes work: a product manager writes a brief, it sits in a backlog, an engineer picks it up, realizes the brief doesn’t answer critical questions, schedules meetings to get clarity, writes a more detailed requirements document, that document goes through review cycles, then someone writes a technical implementation plan, that plan gets reviewed, and finally someone writes the actual code. Each handoff costs time. Each review cycle catches problems that should have been caught earlier. Each queue means someone has to reload context about a feature they looked at days or weeks ago.</p><p>Teams using AI tools in this workflow typically apply them at individual stages. The product manager uses ChatGPT to draft the initial brief faster. The engineer uses Claude to review the PRD for completeness. The developer uses Claude again to generate code more quickly. These are genuine improvements. But the fundamental structure stays the same. You still have handoffs between people with different context. You still have queues where work waits. You still have problems that get caught late when they’re expensive to fix.</p><p>I realized the solution wasn’t making each stage faster with better AI tools. The solution was collapsing the stages entirely and eliminating the handoffs that caused context loss. What if a single integrated system could take a customer request and maintain complete context all the way through to deployed code? What if product managers could specify requirements in natural language, and the system would automatically investigate the codebase, produce a thorough implementation plan reviewed by domain experts, generate the code, verify it works, and raise a pull request?</p><p>That vision required two things working together. First, an organizational commitment to defining requirements more carefully upfront, knowing that those requirements would flow directly into implementation without engineers reinterpreting them. Second, technical infrastructure that could reliably translate those requirements into correct code through intelligent automation. Neither piece works without the other.</p><h3>Building the Infrastructure</h3><p>I started with a simple experiment. I took a feature brief from our product team and sent it directly to Claude with a carefully crafted prompt to generate the implementation code. The code compiled and ran without errors. But when I reviewed it against our existing codebase, the problems became obvious. It didn’t follow our coding standards. Variable naming conventions were different. The code structure didn’t match the design patterns we’d established. Error handling approached problems differently than our existing error handling did.</p><p>The failure revealed something fundamental about how AI models process information. The model was seeing only the feature brief in isolation. It had no context about our existing codebase conventions, our architectural patterns, or the specific constraints that mattered to our team. It generated working code that solved the problem described in the brief, but generic code that could work anywhere rather than code that belonged in our specific codebase. This was the same problem that plagued our human handoff process, just faster.</p><p>I fixed this by focusing on context engineering. Every stage in the automated pipeline now gets the right context it needs to perform its work. Rather than dumping everything into each AI call, I focused on passing only the relevant context each agent actually needed. The investigation agent gets codebase examples and architectural patterns. The planning agent gets the investigative findings plus our technical standards. The code generation agent gets the detailed implementation plan. This selective context approach keeps token costs manageable while ensuring each stage has exactly what it needs. It eliminated about 80% of the revision cycles where I had to manually correct code that didn’t match our standards.</p><p>The orchestration system became more sophisticated. Instead of a linear pipeline using a single model, it became a decision tree that routed each task to the model and agent whose capabilities best matched what that task needed. Deep analytical thinking during requirements validation. Careful reasoning during technical planning. Efficient execution during code generation. All while maintaining perfect context continuity.</p><h3>Making the System Production-Ready</h3><p>I got my first real validation when our CEO requested a new tap-based onboarding flow for our mobile app. I ran the request through the system, and it confidently produced a fully working implementation that handled all the interaction logic, state management, and navigation flows. We handed it off to our design team to add their visual polish, and the feature shipped. This sparked serious interest from the highest levels in our company.</p><p>But I realized the system was missing a critical capability: it couldn’t verify its own work. The system would generate code confidently, produce implementations that compiled and followed our patterns, but it had no feedback loop to check whether that code actually solved the problem correctly in the context of our running application. For frontend development, this gap was particularly problematic. Code might be syntactically correct and architecturally sound, but still fail in practice because a button wasn’t actually clickable or a navigation flow didn’t work as intended.</p><p>This happened right when Anthropic released extended tool capabilities that let Claude execute code, interact with external systems, and spawn specialized sub-agents. I built a visual QA agent that could take the generated functionality and verify the code works as expected by visually inspecting our working application using AI. This agent figures out how to authenticate into our app on its own, how to navigate through the interface to reach the feature it needs to test, and how to actually exercise the requirements that were specified. All of its learnings become documentation it can utilize for future runs. It tests the application the same way a human QA engineer would, but does it automatically as part of the development workflow.</p><p>This was the proof point that showed the system was ready. I could now demonstrate with confidence: if you invest the time to write clear, complete requirements, the system will reliably translate them into working code that actually functions correctly in our application. The automation wasn’t just fast. It was dependable enough to change how we worked.</p><h3>The Organizational Transformation</h3><p>With proven infrastructure in place, I began changing how the organization approached development work. The core insight I shared with everyone was simple. Quality problems caught during planning cost almost nothing to fix. Quality problems caught during code review cost more because someone spent time writing code that needs to be rewritten. Quality problems caught in production cost dramatically more because now you’re dealing with customer impact, emergency fixes, and technical debt.</p><p>This approach, which is called spec driven development, inverts the traditional relationship between planning and coding. In conventional development, you write just enough specification to start coding, then figure out the details during implementation. In spec driven development, you invest heavily in creating a complete, detailed specification first, then treat code generation as a mechanical translation of that spec into syntax. The specification becomes the source of truth, and the code is just one representation of it. This is fundamentally different from documentation-driven development or test-driven development because the specification isn’t just describing what the code should do. It’s the artifact that multiple AI agents have collaborated to create, review, and validate before any code exists.</p><p>There was skepticism about what this meant for different roles in the organization. I reframed what the new process actually enabled. Product managers could now explore different product ideas faster, validating concepts and seeing working implementations without the long feedback cycles of the traditional process. Design could explore new concepts in a working application without needing to create mocks first. Engineers could focus their efforts on proper plan generation, working on multiple bugs or features simultaneously, reviewing and guiding plans in parallel rather than being bottlenecked by serial implementation work.</p><p>Instead of spending time on mechanical translation of ideas into artifacts, people spent time on higher-leverage activities. The team began writing new Agent Skills to improve different domain areas. They worked on new slash commands to further automate various aspects of our organizational processes. The work became more strategic and less tactical across the board. The framework was now a collective effort that was improving our output and efficiency every day.</p><h3>How the Planning Process Works</h3><p>The automated planning workflow became the centerpiece of our new development process. When someone submits requirements, an orchestrating agent manages the entire workflow and ensures every step executes with the same quality bar and verification checks every time.</p><p>The workflow starts with an investigation phase. Instead of jumping straight to planning, the orchestrator delegates exploratory work to a sub-agent whose only job is gathering insight. This investigation agent reads through the existing codebase to understand how similar features are implemented, checks documentation for architectural patterns, and looks at recent changes to see what conventions the team currently uses. All of this investigative work gets compiled into a report that provides context for planning.</p><p>Next, the orchestrator decides whether the requirements involve cross-repository discovery. Our architecture splits frontend and backend code into separate repositories, and features often span both. If the workflow is running on frontend code and the requirements mention anything API related, the system spawns a sub-agent to investigate the backend repository. This cross-repository awareness catches integration issues during planning that would otherwise surface during implementation.</p><p>The plan writing agent takes the requirements and all the investigative work and produces a draft implementation plan. But a single pass isn’t enough. AI models have predictable weaknesses: they sometimes gloss over error handling, occasionally miss performance implications, can be overly optimistic about edge cases. I built multi-phase draft writing where the agent creates an initial draft, then self-audits against a checklist of these known weaknesses. Does this plan handle error cases explicitly? Does it over-engineer the solution? Does it account for backwards compatibility? The agent reviews its own draft against these criteria and revises accordingly.</p><p>At this point I add specialized review. I built a set of 20 review agents, each focused on a specific technical domain. There’s a database migration agent that understands schema changes, indexing strategies, and data migration patterns. There’s a React Native Web agent that knows the quirks of building features that work across mobile and web platforms. There’s a security review agent that checks for common vulnerabilities. The orchestrator uses heuristics to decide which review agents should examine the draft plan. Each review agent files issues with severity levels: blocking, high, medium, or low.</p><p>All this feedback flows to a merge plan agent that synthesizes review comments into a final implementation plan. This agent reasons about which concerns are most important, resolves conflicts between different reviewers, and updates the plan to address legitimate issues while maintaining overall coherence. The result is a final implementation plan that has been investigated, drafted, self-audited, and reviewed by domain specialists.</p><h3>Watching the System Work: A Real Example</h3><p>Here’s a recent feature that went through our system. The product team identified that our onboarding quiz’s health priority question was too limiting. Users could only select a single health priority, but people often have multiple conditions or health focuses they care about. The requirement was straightforward: create a multi-select version of the health priority question and integrate it into both our short and long onboarding quiz variants.</p><h3>9:15 AM: The Request Arrives</h3><p>The ticket lands with clear product context: the current single-select question asks “What is your main health priority?” but users have been asking for the ability to indicate multiple priorities. The proposed solution specifies that the short onboarding quiz should replace the single-select with a multi-select asking “What are all of your current health priorities?” while the long quiz should show both questions back-to-back, single-select first, then multi-select.</p><p>The engineer triggers the orchestration workflow. The system immediately begins the investigation phase, scanning our codebase for the existing quiz implementation. It finds our quiz component architecture, the current health priority question component, the state management patterns we use for quiz responses, and how quiz variants are configured. It also discovers how we persist quiz answers to our backend and what data structures the API expects.</p><h3>9:22 AM: Clarifying Questions</h3><p>Based on the investigation, the system surfaces questions that need answers before planning can proceed. Should users be required to select at least one option, or can they skip the multi-select question entirely? Is there a maximum number of selections? How should the multi-select answers be stored relative to the single-select answer in the long quiz variant, as separate fields or combined? The engineer consults with product and responds: minimum one selection required, no maximum, store as separate fields since we want to preserve the “main” priority distinction.</p><h3>9:31 AM: Plan Generation and Review</h3><p>The plan writing agent produces a detailed implementation plan. It proposes reusing an existing component and adds the necessary state management to track multiple selections, updating the quiz configuration to swap components in the short variant and sequence them in the long variant, and modifying the API payload structure to include the new multi-select field.</p><p>The React Native Web review agent examines the plan and flags that the multi-select component needs to handle both mobile touch interactions and web click interactions properly. It recommends using our existing selection component primitives that already handle cross-platform input. The plan incorporates this guidance.</p><h3>9:48 AM: Implementation Plan Approved</h3><p>The engineer reviews the final plan. It covers the component architecture, state management approach, quiz configuration changes, API contract updates, cross-platform considerations, and backward compatibility with existing user data. Everything aligns with how we build features in this codebase. The engineer approves without modifications.</p><h3>10:12 AM: Code Generated and PR Raised</h3><p>The code generation agent produces the implementation: the modified MultipleChoiceQuestion component, updates to the quiz configuration files, state management changes, and API payload modifications. The code follows our naming conventions, uses the cross-platform primitives the review agent recommended, and includes the data handling approach specified in the plan.</p><p>The visual QA agent spins up the application, navigates to the onboarding flow, and tests both quiz variants. It verifies that the short quiz shows only the multi-select question, that the long quiz shows both questions in sequence, that multiple selections work correctly, and that the minimum-one-selection validation triggers appropriately. All checks pass.</p><p>The pull request goes up. Our automated code review bots run their checks. The engineer reviews the generated code against the approved plan, confirms it matches, and approves. From ticket assignment to approved PR: 57 minutes. The feature that would have taken a day or two of engineering time under our old process shipped before lunch.</p><p>This is the kind of feature that used to feel almost too small to prioritize. The effort required under the old process meant it would sit in the backlog, waiting for a sprint where an engineer had capacity. Now it gets done the same day product identifies the need. Multiply that across dozens of similar improvements per month, and you start to see where the 350% productivity gain comes from.</p><h3>What Changed at the Organizational Level</h3><p>The 350% productivity improvement came from several compounding factors. Features that used to take three days now complete in under one day because we eliminated handoff delays. Quality improved because we catch issues during planning instead of during code review or production. Our bug rate dropped significantly because edge cases that used to slip through vague requirements now get addressed explicitly in implementation plans. Technical debt decreased because specialized review agents catch architectural issues before they become code.</p><p>The bottleneck in our workflow fundamentally changed. Features don’t get stuck waiting for engineers to write code. They get stuck waiting for product managers to decide what to build. That’s exactly where we want the constraint to be. It means our limitation is strategic decision-making, which requires human judgment, not execution work, which can be automated reliably.</p><p>This also changed who can ship features. Product managers who deeply understand customer needs can now ship certain types of features themselves without engineering support. The quality bar shifted from coding ability to requirements definition ability. If you can articulate what needs to be built and why, including edge cases and constraints, the system can build it.</p><p>Engineers didn’t become less important. Their work became more leveraged. Instead of each engineer shipping features serially, one at a time, engineers now design systems and establish patterns that enable many features to ship in parallel through automation. An engineer who builds a specialized review agent for database migrations improves the quality of every future feature that touches the database. An engineer who establishes a new architectural pattern and trains the system on it enables product managers to use that pattern correctly without deep technical knowledge.</p><h3>What This Means for Your Organization</h3><p>The principles I discovered are broadly applicable regardless of what you’re building or what tools you use.</p><p>First, rethink where your organization invests its quality effort. Most teams invest quality effort late in the process during code review and testing. That’s when quality problems are most expensive to fix. The high-leverage move is shifting that investment earlier into planning and requirements definition. This requires cultural change, not just new tools. And cultural change requires courage. You’re asking people who’ve been rewarded for shipping code quickly to instead invest time in planning documents that don’t feel like “real work” to most engineering cultures.</p><p>Second, build or adopt automation that makes the quality shift viable. Asking people to invest more in planning only works if that planning reliably translates into good execution. You need infrastructure that maintains context across your entire workflow, routes different types of work to appropriate capabilities, and verifies outputs against reality.</p><p>Third, focus on consistency and repeatability. The organizational value comes not from occasionally producing great plans but from producing good plans every single time. Automated workflows that execute the same way regardless of who uses them or when create the reliability that enables organizational change. People will only change their behavior if they trust the new process works.</p><p>Fourth, design for interactive refinement rather than perfect upfront specification. My system asks clarifying questions when requirements are ambiguous. This is better than requiring perfect requirements upfront because it meets people where they are and guides them toward completeness.</p><p>The meta-lesson from this transformation is that AI productivity at scale isn’t about finding better AI tools. It’s about identifying where your current process creates waste and friction, then using AI to eliminate that waste rather than just making the existing process faster. I didn’t make our old process 350% faster. I built a new process that eliminated most of what made the old process slow.</p><p>For business leaders, this suggests your AI investment strategy should focus less on productivity tools and more on process transformation enabled by automation. The models will keep improving. The tools will keep evolving. What won’t change is the need to rethink workflows from first principles and build infrastructure that makes new workflows viable.</p><p>For engineers, this means the valuable skill isn’t learning to prompt AI better. It’s learning to design systems where AI handles execution reliably so humans can focus on the strategic decisions that require judgment. Think less about “how do I get AI to write better code” and more about “how do I build a process where code quality is determined by planning quality, and AI reliably translates good plans into good code.”</p><p>The shift from “AI as tool” to “AI as organizational infrastructure” is available to any team willing to rethink their workflows from first principles. The 350% productivity gain I achieved came from making that shift and building the systems that made it work. Your organization’s version will look different in the details, but the principles are the same. Invest quality effort early. Build automation that’s reliable enough to trust. Design for consistency. Enable people rather than replacing them.</p><p>That’s how you turn AI from an interesting capability into a genuine productivity multiplier.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a99f5da119ae" width="1" height="1" alt=""><hr><p><a href="https://medium.com/swlh/how-we-increased-productivity-by-350-using-ai-a99f5da119ae">How We Increased Productivity by 350% using AI</a> was originally published in <a href="https://medium.com/swlh">The Startup</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Securing a Room Database With Passcode Based Encryption]]></title>
            <link>https://medium.com/vmware-end-user-computing/securing-a-room-database-with-passcode-based-encryption-82ec670961e?source=rss-f5f2ae2e19f7------2</link>
            <guid isPermaLink="false">https://medium.com/p/82ec670961e</guid>
            <category><![CDATA[kotlin]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[mobile]]></category>
            <category><![CDATA[encryption]]></category>
            <category><![CDATA[engineering]]></category>
            <dc:creator><![CDATA[Daniel Ochoa]]></dc:creator>
            <pubDate>Mon, 22 Jun 2020 16:54:35 GMT</pubDate>
            <atom:updated>2020-06-23T20:08:10.618Z</atom:updated>
            <content:encoded><![CDATA[<h3>Securing a Room Database With Passcode-Based Encryption</h3><h4>Using available Java APIs</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gMch-7Lyxat7q6JWEr7JuQ.jpeg" /></figure><p>As developers we are often tasked with securing the data we store in our applications. In a previous <a href="https://medium.com/@gameboy45/organized-secure-storage-encryptedsharedpreferences-72b2d71a8558">article</a> I talked about how to secure arbitrary data using Android’s <a href="https://developer.android.com/reference/androidx/security/crypto/EncryptedSharedPreferences">EncryptedSharedPreferences</a>. In this post, I’m going to talk about encrypting <a href="https://developer.android.com/jetpack/androidx/releases/room">Room</a> with <a href="https://www.zetetic.net/sqlcipher/">SQLCipher</a> using PBE (Passcode Base Encryption).</p><h3>What is PBE?</h3><p>To summarize, PBE is a popular method for creating strong cryptographic encryption keys based on a user-supplied passcode. Without access to the user passcode, you can not decrypt the database, which means the user’s data is secure. Below is a diagram explaining how a user’s password is used to encrypt the database key which can then be safely stored away in insecure storage.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*k2NQx-OCuGYZJQzZRrERgw.png" /><figcaption>PBE Diagram</figcaption></figure><h3>What is SQLCipher</h3><p>SQLCipher is an extension to <a href="https://www.sqlite.org/index.html">SQLite</a> which allows for 256-bit encryption of SQLite databases. You can use the SQLCipher namespace instead of the identically named SQLite APIs for an easy transition.</p><h4>Required dependencies</h4><p>You’ll need to add these dependencies in order to add support for encrypting your Room database.</p><pre>implementation &quot;net.zetetic:android-database-sqlcipher:4.4.0&quot;<br>implementation &quot;androidx.sqlite:sqlite:2.1.0&quot;</pre><h3>SQLCipher key formats</h3><p>There are three different key formats that SQLCipher supports. They are listed here so you’re aware of your options but for this guide we’ll be focusing on the “Raw key data” format.</p><h4>Passphrase with key derivation</h4><p>This option takes the user’s passcode and converts it to a key using <a href="http://en.wikipedia.org/wiki/PBKDF2">PBKDF2 key derivation</a>. This is the slowest option as it delays the opening of the database in order to perform this conversion.</p><h4>Raw key data</h4><p>This method uses the raw key bytes, that we’ll be creating below, to decrypt the database. The expected format is a 64 character hex encoded string which will be converted directly to 32 bytes (256 bits) of key data.</p><h4>Raw key data with explicit salt</h4><p>Lastly, you can optionally provide a database salt along with the raw key if desired. Normally SQLCipher generates a database salt and stores it in the first 16 bytes of the database. This key method requires 96 characters hex encoded in a BLOB .</p><h3>Overview</h3><p>Here’s a breakdown of what we’ll be discussing:</p><ul><li>Generate a random key</li><li>SQLCipher key formats</li><li>Create a hex encoded db key</li><li>PBE encrypt + store the database key</li><li>Restore + decrypt the database key</li><li>Encrypt your Room database</li><li>Things to know about PBE</li><li>Summary</li></ul><h3>Generate a random key</h3><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7c8962d0410359ae3aa60f638f6ebb0a/href">https://medium.com/media/7c8962d0410359ae3aa60f638f6ebb0a/href</a></iframe><p>Let me explain what’s going on above. On API 26 (Oreo) and above we have access to <a href="https://developer.android.com/reference/java/security/SecureRandom#getInstanceStrong()">SecureRandom.getInstanceStrong()</a>, which will ensure a suitable, strong SecureRandom instance is used for generating a random value. We pass in 32 as that is how many bytes we want the key to be (256 bits). For older APIs, we’ll just use the default <a href="https://en.wikipedia.org/wiki/Pseudorandom_number_generator">PRNG</a> the system has identified.</p><p><strong>Note:</strong> <em>The above will produce a pseudo random number. The issue is on some OEMs and APIs, there is not enough entropy which can result in a vulnerability where your random number isn’t random enough and can be predictable. This affects all Java APIs on Android. I’ll leave this for another discussion, though, as there isn’t an answer for it at the Java layer. In most cases this is sufficient.</em></p><h3>Create a hex encoded db key</h3><p>So now that we have a raw byte key let us put it in the <a href="https://www.zetetic.net/sqlcipher/sqlcipher-api/#example-2-raw-key-data-without-key-derivation">hex encoded format</a> that <a href="https://www.zetetic.net/sqlcipher/">SQLCipher</a> is looking for.</p><p>Let’s first create a nifty extension function for converting a ByteArray to a hex encoded CharArray.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/99399f932d98983a2b5b7aff28131462/href">https://medium.com/media/99399f932d98983a2b5b7aff28131462/href</a></iframe><p>Now let’s utilize this function to create a random key and then convert it to hex encoded CharArray.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/963d29c3482d010ebd5bf134d3f155dd/href">https://medium.com/media/963d29c3482d010ebd5bf134d3f155dd/href</a></iframe><h3>PBE encrypt + store the database key</h3><p>At this point we have a valid database key that you can use to key your Room database and begin using it. But we want to be able to store this key to disk so we have it if the app is killed or the device is rebooted. So, without further ado let’s jump in.</p><h4>Encapsulate the data we need to store</h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/347f138ac48cc548a570a1c13bb718ef/href">https://medium.com/media/347f138ac48cc548a570a1c13bb718ef/href</a></iframe><p>Here we have a simple data class that encapsulates everything we need to be able to decrypt this database later on.</p><h4>Encrypt the database key using PBE</h4><p>Here’s the fun part. Let’s take the user’s passcode and encrypt the database key so we can store it in <a href="https://developer.android.com/reference/android/content/SharedPreferences">SharedPreferences</a> securely.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/46880856d16e998ef7c51c16d6e67305/href">https://medium.com/media/46880856d16e998ef7c51c16d6e67305/href</a></iframe><p>What we’ve done is encrypted the database key with the user’s passcode using the AES algorithm and then converted the initialization vector + encrypted key + salt into base64 format so it can be stored as a String.</p><h4>Persist the key to disk</h4><p>Now let’s take this Storable object and persist it to <a href="https://developer.android.com/reference/android/content/SharedPreferences">SharedPreferences</a>.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7903b4cbecefef54e708535d18d4e9dd/href">https://medium.com/media/7903b4cbecefef54e708535d18d4e9dd/href</a></iframe><p>Our database key is now encrypted using a KEK (key encrypting key) and persisted to disk so we can decrypt the database when the app gets killed or the device gets rebooted.</p><h3>Restore + decrypt the database key</h3><p>Now let’s show how to do everything in reverse so you can decrypt the database key and use it.</p><h4>Retrieve our Storable instance from prefs</h4><p>We previously stored a serialized copy of our Storable instance in SharedPreferences as a JSON String. Let’s retrieve that JSON String and deserialize it back to a Storable instance.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/644453be49c61f220841ab957f1ffdd8/href">https://medium.com/media/644453be49c61f220841ab957f1ffdd8/href</a></iframe><h4>Decrypt the raw byte key</h4><p>We’ll take our storable instance along with the user passcode and decrypt the aesWrappedKey to obtain the raw byte key.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ad9dbe0e202a16cc7df8667bf74222e1/href">https://medium.com/media/ad9dbe0e202a16cc7df8667bf74222e1/href</a></iframe><h4>Hex encode the decrypted raw byte key</h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8b2ea38648e3c5a44600093001de1299/href">https://medium.com/media/8b2ea38648e3c5a44600093001de1299/href</a></iframe><p>Here we retrieved the serialized Storable instance from prefs, decrypted the raw byte key, and then created a hex encoded db key from the raw byte key. We now have everything we need to again decrypt the database.</p><h3>Encrypt your Room database</h3><p>Now let’s show how to encrypt that Room database. Thankfully, SQLCipher has now added support for Room encryption so let’s look at what this looks like.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/38a416debd7917a71abdd9c290b4f177/href">https://medium.com/media/38a416debd7917a71abdd9c290b4f177/href</a></iframe><p>And that’s it. Your database is now encrypted. Simple as that.</p><h3>Things to know about PBE</h3><p>Encrypting your database with PBE means without the user’s passcode you will not be able to decrypt your database. That means your application’s logic will need to completely change to accommodate this. Any attempts to query this database before it has been decrypted will result in an app crash. To be clear, once you’ve decrypted the database everything will be fine. But if the app is killed or the device is rebooted then you no longer have a decrypted database and you will now need to prompt the user for a passcode. So, you’ll need to think about your application design to ensure when the database is encrypted you have no code that will attempt to access it. After implementing PBE, make sure you do thorough testing around this. It would make sense to create a singleton that manages the locked state of your application so after the passcode has been supplied and database successfully decrypted, then the locked state becomes unlocked and your application code is then free to access the db.</p><h3>Summary</h3><p>To finish, you’ll just need to wire up a passcode screen and make sure none of your code accesses this database until you’ve unlocked the application with the user’s passcode. Under no circumstances should you save the user’s passcode as that would defeat all of the security we’ve just implemented. You can take this a step further and implement a timeout for your session so that after five minutes or one hour you unset rawByteKey, dbCharKey, shutdown your database, and require the user to re-authenticate.</p><p>Thank you for reading along and I hope you learned something today that can help you in your project. If you’ve found this useful, <a href="https://twitter.com/shafty023">hit me up on Twitter</a>!</p><h4>References</h4><ul><li><a href="https://www.zetetic.net/sqlcipher/sqlcipher-for-android/">https://www.zetetic.net/sqlcipher/sqlcipher-for-android/</a></li><li><a href="https://www.sqlite.org/index.html">https://www.sqlite.org/index.html</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=82ec670961e" width="1" height="1" alt=""><hr><p><a href="https://medium.com/vmware-end-user-computing/securing-a-room-database-with-passcode-based-encryption-82ec670961e">Securing a Room Database With Passcode Based Encryption</a> was originally published in <a href="https://medium.com/vmware-end-user-computing">VMware 360</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Organized Secure Storage — EncryptedSharedPreferences]]></title>
            <link>https://medium.com/vmware-end-user-computing/organized-secure-storage-encryptedsharedpreferences-72b2d71a8558?source=rss-f5f2ae2e19f7------2</link>
            <guid isPermaLink="false">https://medium.com/p/72b2d71a8558</guid>
            <category><![CDATA[android]]></category>
            <category><![CDATA[engineering]]></category>
            <category><![CDATA[kotlin]]></category>
            <category><![CDATA[mobile]]></category>
            <category><![CDATA[cryptography]]></category>
            <dc:creator><![CDATA[Daniel Ochoa]]></dc:creator>
            <pubDate>Mon, 25 May 2020 19:11:52 GMT</pubDate>
            <atom:updated>2020-07-07T12:31:35.702Z</atom:updated>
            <content:encoded><![CDATA[<h3>Organized Secure Storage — EncryptedSharedPreferences</h3><h4>Introducing DataStore — A secure approach to organizing your prefs usage</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/960/0*0dglF6ID5wa5eS1C.jpg" /></figure><p>Android recently released a couple crypto application program interfaces (APIs) as part of Android Jetpack which are <a href="https://developer.android.com/reference/androidx/security/crypto/EncryptedSharedPreferences">EncryptedSharedPreferences</a> and <a href="https://developer.android.com/reference/androidx/security/crypto/EncryptedFile">EncryptedFile</a>. We’ll be focusing on EncryptedSharedPreferences and show how to build a generic abstraction on top that allows the developer to not only provide secure storage of arbitrary data, but also re-think the usage of preferences.</p><h3>Storing data</h3><p>There are a few different ways of storing data depending on the use case. Here are a few to mention:</p><ul><li><a href="https://developer.android.com/reference/android/content/SharedPreferences">SharedPreferences</a></li><li><a href="https://www.sqlite.org/index.html">SQLite</a></li></ul><h4>SharedPreferences</h4><p>SharedPreferences provides an abstraction over a flat file on disk that allows for writing key/value pairs to a clear text file in your app’s directory. Under normal situations this is perfectly secure as your app’s directory is protected by Android’s sandbox environment.</p><h4>SQLite</h4><p>For large volumes of data that need to be queried often, or used as part of UI rendering, the developer will likely be using a SQLite database. The recommended abstraction over SQLite is to use <a href="https://developer.android.com/training/data-storage/room">Room</a> rather than SQLite directly but it’s still SQLite behind the scenes.</p><h3>What is EncryptedSharedPreferences?</h3><p>This is a version of SharedPreferences that encrypts the keys and values before storing them to the flat file on disk. All of the methods used with SharedPreferences are intact so it’s a seamless integration.</p><h4>Why is EncryptedSharedPreferences necessary?</h4><p>If an app directory is protected against access, then why does the developer need an encrypted version? If an app is installed on an emulator or rooted device, it has instant access to a lot of your configuration settings, or worse, it may store some serialized objects as JSON into SharedPreferences. Now it’s exposed some internals of the app that the developer didn’t want exposed. Or maybe the developer works for a company that can’t afford to have any data at rest unencrypted. Here comes EncryptedSharedPreferences to the rescue.</p><h3>Overview</h3><p>Here’s a quick overview of what I will be going over today.</p><ul><li>Setup</li><li>DataStore</li><li>A full implementation of DataStore</li></ul><h4>Setup</h4><p>Add the following to your build.gradle file.</p><p><strong>Note:</strong> Keep in mind you’ll need to change your minSdkVersion to 23 due to an internal dependency on the <a href="https://github.com/google/tink">Tink</a> crypto library.</p><pre>implementation(&quot;androidx.security:security-crypto:1.0.0-rc02&quot;)</pre><h3>DataStore</h3><p>With SharedPreferences the typical developer will place all of the app’s key-value pairs into a single class that becomes unmanageable. DataStore is a generic abstraction over EncryptedSharedPreferences that gives the developer a way to organize our preferences into meaningful collections.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c1dd8afd98a9a23b1ebfc68b48ce60d4/href">https://medium.com/media/c1dd8afd98a9a23b1ebfc68b48ce60d4/href</a></iframe><p>Let’s talk about what we have above.</p><h4>annotation class Key</h4><p>This allows a class to define the key where its data will be stored and allows for one less argument to be passed into the restore/save methods.</p><h4>sharedPrefs</h4><p>This is our instance of EncryptedSharedPreferences that is initialized with the recommended defaults.</p><h4>restore</h4><p>This method takes two arguments. The first is the class that is needed to restore which is required to have the above annotation class defined for it. The second argument is a function block that takes a nullable String (the serialized data retrieved from SharedPrefs) and produces a nullable generic T instance.</p><h4>save</h4><p>This method takes the instance of the class that was returned from a call to restore and a function block that takes in the first argument and produces a serialized representation that can be stored to SharedPreferences.</p><h3>Wrapping this up into an implementation</h3><p>First we need to settle on a serializer/de-serializer so for this example we’ll use <a href="https://github.com/google/gson">GSON</a>.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7c1ea81a9ad3fc85ddbf880136ea4006/href">https://medium.com/media/7c1ea81a9ad3fc85ddbf880136ea4006/href</a></iframe><p>Quick explanation on the above code. De-serialize is reified so the generic type is kept and can be utilized by Gson() to restore the correct class type.</p><p>Now let’s pull this into an actual implementation:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5e72e68dfa72cb728a4bef4cb9fc9eb1/href">https://medium.com/media/5e72e68dfa72cb728a4bef4cb9fc9eb1/href</a></iframe><p>And there you have it. A simple abstraction over EncryptedSharedPreferences that gives the developer secure storage and helps to organize the data into relevant classes. This is a singleton that persists the state even after the app is killed. All of its data is stored in encrypted storage and handles deserialization/serialization easily. I personally use <a href="https://github.com/google/dagger">Dagger</a> for DI, which simplifies injecting the constructor parameters. This allows me to return a regular SharedPreference in a unit test since unit tests don’t have access to crypto libraries.</p><p>Just for giggle, let’s look at what this would have looked like using just Preferences.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d9eede51811da5b3c5b9034de06c4afa/href">https://medium.com/media/d9eede51811da5b3c5b9034de06c4afa/href</a></iframe><p>Imagine this class filled with hundreds of preference keys all tracking unrelated data. Just messy.</p><h3>Summary</h3><p>Thanks everyone for reading and I hope you were able to take something away from this that can be put to use. If anyone is interested in what tests (unit + connected) would look like for this, please let me know in the comments. If you’ve found this useful, <a href="https://twitter.com/shafty023">hit me up on Twitter</a>!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=72b2d71a8558" width="1" height="1" alt=""><hr><p><a href="https://medium.com/vmware-end-user-computing/organized-secure-storage-encryptedsharedpreferences-72b2d71a8558">Organized Secure Storage — EncryptedSharedPreferences</a> was originally published in <a href="https://medium.com/vmware-end-user-computing">VMware 360</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Writing Thorough Unit Tests]]></title>
            <link>https://medium.com/swlh/writing-thorough-unit-tests-591292d5a571?source=rss-f5f2ae2e19f7------2</link>
            <guid isPermaLink="false">https://medium.com/p/591292d5a571</guid>
            <category><![CDATA[unit-testing]]></category>
            <category><![CDATA[kotlin]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[testing]]></category>
            <dc:creator><![CDATA[Daniel Ochoa]]></dc:creator>
            <pubDate>Mon, 25 May 2020 04:56:10 GMT</pubDate>
            <atom:updated>2020-05-25T16:36:03.036Z</atom:updated>
            <content:encoded><![CDATA[<h4>A pragmatic approach to improving your unit tests</h4><p>As software developers we all know how important it is to unit test the code that we write. Some of us write tests that verify the happy paths only (bad) and others look for high code coverage numbers. But how many of you are actually writing thorough tests? Let’s take a look at what this means.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1006/1*iM0aWqlGY-GTLuGSNWBwLg.png" /><figcaption>Characteristics of a good unit test</figcaption></figure><p><strong>Thorough -</strong> Test normal &amp; failure conditions, invalid inputs, and boundary conditions.</p><p><strong>Repeatable -</strong> Tests must always give you the same results every time so avoid depending on things that might change such as an external server.</p><p><strong>Focused -</strong> Tests should exercise one specific aspect of your code at a time. A failure in a unit test should lead you to an actual bug in your code.</p><p><strong>Verifies Behavior -</strong> Tests should test behavior without making assumptions on implementations. Avoid over mocking with Mockito.</p><p><strong>Fast -</strong> Tests should be fast since 70% of your tests should consist of unit tests.</p><p><strong>Concise -</strong> Tests should be easy to understand and be a clear blueprint of what the code under test is doing.</p><h3>Test 1: Not Repeatable</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RqYxc2EN76e_MSSvVr_waA.png" /></figure><p>Above we see a test that is testing SomeClass#getCurrentMonthString. Way too often I see this mistake made during code reviews and it violates the repeatability characteristic. The reason is the default locale, timezone, and system time are being used. This means 1 month from now this test will return March instead of February which will instantly begin failing.</p><p>Let’s see how this same test looks with these issues fixed.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*a1BvjZvGpGBEURZJ-Av_Pg.png" /></figure><p>Here we can see we preset the timezone, locale, and timestamp so that we obtain consistent results.</p><h3>Test 2: Not Fast + Repeatable + Thorough</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*iZhb5yPrGOu_-j2fGj7COw.png" /></figure><p>This test just hurts me to look at. First off it’s doing network io in an actual unit test. Unit tests should be hermetic and mock network io so you mock responses and error conditions (401/503/200) to make sure your code handles every possibility.</p><p>It includes a sleep statement with some magical expectation that every time it’s run it will only take 10s to finish the network call. Please don’t use sleep statements EVER.</p><p>It’s also testing a method that performs some work asynchronously. Tests should always test against synchronous code.</p><h3>Test 3: Not Thorough</h3><p>Let’s assume we have a calculator class that provides addition, subtraction, multiplication, and division.</p><p>Here we have two test functions for addition and subtraction. Each test has verified the core function is working as intended.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/848/1*ePl8TiY8lyfc99LlhgSyww.png" /></figure><p>While this will tick the checkbox for increased code coverage it’s clearly violating the thorough characteristic. You can’t just test the happy paths. You have to be extremely thorough and think of every possible way you can break your code and write tests accordingly. You should be adding two positive numbers, adding a positive &amp; a negative number, a negative and a negative number, etc. You get the picture. Do not just test a single condition and move on. That’s not going to keep bugs from showing up in production code.</p><h3>Test 4: Not Verifying Behavior</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qojKQ5Ajvg5KnbaqGnGNIQ.png" /></figure><p>Here we have a custom EditText view that overrides the setText() function and prepends “vm-” to anything passed in. Let me explain why this is a bad test and why you should avoid Mockito.verify(). The common thinking here is that since EditText comes with Android then it has it’s own unit tests already so we don’t need to verify that it’s working.</p><p>Let’s say 6 months down the road someone wants to introduce a new parent class named CleanupEditText and one of its jobs is to strip out dashes from any input string. In this example with only a few lines of code it’s very easy to see where I’m going with this but imagine this class has 1000+ lines of code. Now the dev changes the parent class of MyEditText to this new class and runs all the tests to verify he hasn’t broken anything. The test that was written for MyEditText passes because all it is doing is verifying that the parent instance of setText() was called.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zqhdmwMxDbkf0bwVQbNR3Q.png" /></figure><p>Now we’ve broken the expected behavior and have no way of knowing because the above test is not verifying behavior. It is only verifying a method is being called.</p><p>Here is that same test fixed so it verifies behavior.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1017/1*Cpmrsz6LaAYFOoDWI9r91g.png" /></figure><p>How easy was that? Yet it’s so instinctive to reach for Mockito.verify() and abuse it without thinking of the possible consequences.</p><h3>Test 5: Not Focused</h3><p>Now let’s assume we have a class named Calculator again with basic mathematical operations supported.</p><p>Now someone writes a single test function called testOperations as shown below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/972/1*G4CtDFgvww9GB-a525rqmg.png" /></figure><p>We should ensure we are identifying units of code and testing those separately otherwise you end up with an integration test as shown above. Remember, this article is about improving your unit tests and unit tests test business logic in isolation.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PdvvA8lUx8SwuMveGnhR6A.png" /></figure><p>Here we have the same test broken up into 3 focused unit tests that are each testing only a single aspect of your code. The test function names have also been modified to more clearly explain what is being tested, with what inputs, and expected result.</p><h3>Test 6: Not Concise + Thorough</h3><p>Here we have a class named AnnualPayCalculator that computes an annual pay given hourly pay and total weekly hours worked.</p><p>Below you’ll see a test function that verifies the expected result is returned.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UjvpX-aaFTC4iU3P4XklMQ.png" /></figure><p>The main concern here is this test is not concise. It’s way too verbose and requires you to really read the test to understand what’s being tested.</p><p>Here is the same test written more concisely.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1022/1*33ZQZmjtxSqY5-qbMyzuQg.png" /></figure><h3>Test Naming</h3><p>This brings us to our last characteristic of a good unit test that was not called out previously. Naming.</p><p>This is sure to be controversial because on one hand you are used to writing shorter function names in production code.</p><p>But, for test functions, there’s a crucial factor that changes the equation: you never write <em>calls</em> to test functions. A developer types out a test name exactly once — in the function signature. Given this, brevity still matters, but it matters less than in production code.</p><p>Whenever a test breaks, the test name is the first thing you see, so it should communicate as much as possible.</p><p><strong>Format:</strong></p><pre>when_expected<br>when_with_expected</pre><p><strong>Bad examples:</strong></p><pre>testOnActivityCreated<br>testGetHashedAttachmentFilenames</pre><p><strong>Good examples:</strong></p><pre>viewCreated_listViewExists<br>getHashedAttachmentFilenames_withNullList_emptyStringReturned</pre><h3>Summary</h3><ul><li>Don’t just write unit tests. Include integration and workflow where needed. Don’t waste time on these if they aren’t absolutely necessary to cover something that isn’t already being tested.</li><li>Make sure your tests follow the characteristics of a good unit test</li><li>Name your tests properly</li><li>A failure in a test should immediately tell you exactly what is broken and under what condition</li><li>Always strive to test functionality/behavior. Verifying a method is called only should be rarely used</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=591292d5a571" width="1" height="1" alt=""><hr><p><a href="https://medium.com/swlh/writing-thorough-unit-tests-591292d5a571">Writing Thorough Unit Tests</a> was originally published in <a href="https://medium.com/swlh">The Startup</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>