By using this site, you agree to the Privacy Policy and Terms of Use.
Accept
World of SoftwareWorld of SoftwareWorld of Software
  • News
  • Software
  • Mobile
  • Computing
  • Gaming
  • Videos
  • More
    • Gadget
    • Web Stories
    • Trending
    • Press Release
Search
  • Privacy
  • Terms
  • Advertise
  • Contact
Copyright © All Rights Reserved. World of Software.
Reading: Flip the Script: Write the Tests, Let AI Write the Implementation | HackerNoon
Share
Sign In
Notification Show More
Font ResizerAa
World of SoftwareWorld of Software
Font ResizerAa
  • Software
  • Mobile
  • Computing
  • Gadget
  • Gaming
  • Videos
Search
  • News
  • Software
  • Mobile
  • Computing
  • Gaming
  • Videos
  • More
    • Gadget
    • Web Stories
    • Trending
    • Press Release
Have an existing account? Sign In
Follow US
  • Privacy
  • Terms
  • Advertise
  • Contact
Copyright © All Rights Reserved. World of Software.
World of Software > Computing > Flip the Script: Write the Tests, Let AI Write the Implementation | HackerNoon
Computing

Flip the Script: Write the Tests, Let AI Write the Implementation | HackerNoon

News Room
Last updated: 2025/11/27 at 10:22 AM
News Room Published 27 November 2025
Share
Flip the Script: Write the Tests, Let AI Write the Implementation | HackerNoon
SHARE

Test-Driven Development (TDD) is widely accepted as the gold standard for producing robust, reliable, and refactorable software.

We also know the reality: TDD is exhausting.

In the heat of a sprint, when a deadline is looming, TDD is often the first casualty. Why? Because TDD requires you to constantly switch cognitive gears. You have to wear the “adversarial tester” hat to define the requirements, and then immediately switch to the “problem-solver” hat to write the implementation. Doing both simultaneously drains mental energy fast.

As a result, many teams revert to “Test-After Development” (TAD), writing tests only after the feature works “on my machine.” This leads to brittle tests that often just confirm the biases of the implementation code already written.

The AI Pivot: A New Workflow

We are entering an era where generative AI is surprisingly good at writing boilerplate implementation code, but still mediocre at deep, contextual system design and understanding nuanced business requirements.

So, let’s play to our strengths and outsource our weaknesses.

The proposed workflow is simple but transformative:

  1. Human: Writes the Unit Tests (The “Red” phase).
  2. AI: Writes the Implementation to pass those tests (The “Green” phase).
  3. Human: Reviews the code and refactors if necessary (The “Refactor” phase).

Why This Works

The hardest part of programming isn’t remembering syntax; it’s defining exactly what the software should do.

When you write tests first, you are forced to crystallize the requirements before a single line of production code exists. You are defining the API surface area, expected inputs, and required outputs. This is high-value cognitive work that requires human context.

Once those constraints are codified in a test suite, the actual implementation is often just “connect-the-dots” logic. LLMs (like GPT-4, Claude, or Copilot) excel at connect-the-dots.

A Practical Example: The Discount Calculator

Let’s look at a simple, real-world scenario. We need a function that calculates the total price of a shopping cart, applying a 10% discount if the total is over $100. Let’s use JavaScript and Jest.

Step 1: The Human writes the tests

I am not thinking about how to write the loop or the if-statement yet. I am only thinking about the desired behavior.

// cartCalculator.test.js
const { calculateTotal } = require('./cartCalculator');

describe('Shopping Cart Calculator', () => {
    test('should return 0 for an empty cart', () => {
        expect(calculateTotal([])).toBe(0);
    });

    test('should calculate total correctly for carts under $100 (no discount)', () => {
        const cart = [
            { name: 'Book', price: 30 },
            { name: 'Coffee', price: 20 }
        ];
        // Total is 50. No discount.
        expect(calculateTotal(cart)).toBe(50);
    });

    test('should apply a 10% discount for carts over $100', () => {
         const cart = [
            { name: 'Keyboard', price: 80 },
            { name: 'Mouse', price: 40 }
        ];
        // Total is 120. 10% discount is $12. Final price should be 108.
        expect(calculateTotal(cart)).toBe(108);
    });

    test('should handle edge case where total is exactly $100 (no discount)', () => {
         const cart = [
            { name: 'Item A', price: 50 },
            { name: 'Item B', price: 50 }
        ];
        // Total is exactly 100. Discount threshold is > 100.
        expect(calculateTotal(cart)).toBe(100);
    });
});

If I run this now, it fails :red_circle:. Perfect.

Step 2: The AI writes the implementation

Now, I switch to my LLM of choice. I don’t need to explain the business logic to it in English prose. The tests are the explanation.

My Prompt:

“I have a JavaScript test file below for a shopping cart calculator. Please write the implementation file cartCalculator.js so that all these tests pass. Use clean, modern JavaScript syntax.”

[Paste the test code from Step 1 here]

The AI Output (GPT-4 in this instance):

// cartCalculator.js

/**
 * Calculates the total price of a cart, applying a 10% discount
 * if the gross total exceeds $100.
 * @param {Array<{name: string, price: number}>} cartItems
 * @returns {number}
 */
function calculateTotal(cartItems) {
    if (!cartItems || cartItems.length === 0) {
        return 0;
    }

    const grossTotal = cartItems.reduce((sum, item) => sum + item.price, 0);
    const DISCOUNT_THRESHOLD = 100;
    const DISCOUNT_RATE = 0.10;

    if (grossTotal > DISCOUNT_THRESHOLD) {
        const discountAmount = grossTotal * DISCOUNT_RATE;
        return grossTotal - discountAmount;
    }

    return grossTotal;
}

module.exports = { calculateTotal };

Step 3: Verify and Refactor

I save the AI’s code and run my test suite.

PASS  ./cartCalculator.test.js
✓ should return 0 for an empty cart (2 ms)
✓ should calculate total correctly for carts under $100 (no discount) (1 ms)
✓ should apply a 10% discount for carts over $100 (1 ms)
✓ should handle edge case where total is exactly $100 (no discount) (1 ms)

It’s Green.

I review the code. It’s actually quite good. It used reduce, handles the empty array check correctly, and even used constants for magic numbers like the threshold rate. I might rename a variable or two to fit team style guides, but the heavy lifting is done.

The Benefits of AI-Driven TDD

1. Guaranteed Test Coverage By definition, every line of code written by the AI exists solely to satisfy a test you wrote. You can’t “forget” to test a branch condition if the code for that branch only exists because a test demanded it.

2. Better Requirements Gathering If you write a vague test, the AI will write vague code. This workflow forces you to be extremely precise about edge cases (like the “exactly $100” example above) before implementation begins.

3. Mental Energy Conservation You stay focused on the “What” (the tests). You outsource the “How” (the implementation syntax) to the AI, treating it like a very fast junior developer parked next to you.

The Pitfall: Garbage In, Garbage Out

This workflow is not magic. It relies entirely on the quality of your tests.

If you write lazy tests that don’t cover edge cases, the AI will write lazy code that breaks in production. If your tests are tightly coupled to implementation details rather than behavioral outcomes, the AI’s output will be brittle.

The human remains the architect and the gatekeeper of quality. The AI is just the contractor laying the bricks based on your blueprints.

Conclusion

TDD is difficult to sustain because it requires discipline and constant context-switching. By using AI to handle the implementation phase, we can lower the barrier to entry for true TDD.

Don’t ask AI to write code and then try to figure out how to test it later. Write the tests first, and force the AI to earn its keep by passing them.

Sign Up For Daily Newsletter

Be keep up! Get the latest breaking news delivered straight to your inbox.
By signing up, you agree to our Terms of Use and acknowledge the data practices in our Privacy Policy. You may unsubscribe at any time.
Share This Article
Facebook Twitter Email Print
Share
What do you think?
Love0
Sad0
Happy0
Sleepy0
Angry0
Dead0
Wink0
Previous Article PlayStation gamers unlock five FREE games in December Christmas giveaway PlayStation gamers unlock five FREE games in December Christmas giveaway
Next Article AI explodes the memory market AI explodes the memory market
Leave a comment

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Stay Connected

248.1k Like
69.1k Follow
134k Pin
54.3k Follow

Latest News

Bloody Wolf Expands Java-based NetSupport RAT Attacks in Kyrgyzstan and Uzbekistan
Bloody Wolf Expands Java-based NetSupport RAT Attacks in Kyrgyzstan and Uzbekistan
Computing
Let’s play roulette: Samsung Galaxy S25 Ultra showing different awesome deals for different people!
Let’s play roulette: Samsung Galaxy S25 Ultra showing different awesome deals for different people!
News
Apple Granted Reset on New Campus Deal
Apple Granted Reset on New Campus Deal
News
The HackerNoon Newsletter: Everyones Using the Wrong Algebra in AI (11/27/2025) | HackerNoon
The HackerNoon Newsletter: Everyones Using the Wrong Algebra in AI (11/27/2025) | HackerNoon
Computing

You Might also Like

Bloody Wolf Expands Java-based NetSupport RAT Attacks in Kyrgyzstan and Uzbekistan
Computing

Bloody Wolf Expands Java-based NetSupport RAT Attacks in Kyrgyzstan and Uzbekistan

4 Min Read
The HackerNoon Newsletter: Everyones Using the Wrong Algebra in AI (11/27/2025) | HackerNoon
Computing

The HackerNoon Newsletter: Everyones Using the Wrong Algebra in AI (11/27/2025) | HackerNoon

3 Min Read
Engineering Intelligence: Visionary of Autonomous Infrastructure and Fluid Digital Evolution | HackerNoon
Computing

Engineering Intelligence: Visionary of Autonomous Infrastructure and Fluid Digital Evolution | HackerNoon

0 Min Read
Vodacom Tanzania expands M-Pesa with cross-border payments
Computing

Vodacom Tanzania expands M-Pesa with cross-border payments

4 Min Read
//

World of Software is your one-stop website for the latest tech news and updates, follow us now to get the news that matters to you.

Quick Link

  • Privacy Policy
  • Terms of use
  • Advertise
  • Contact

Topics

  • Computing
  • Software
  • Press Release
  • Trending

Sign Up for Our Newsletter

Subscribe to our newsletter to get our newest articles instantly!

World of SoftwareWorld of Software
Follow US
Copyright © All Rights Reserved. World of Software.
Welcome Back!

Sign in to your account

Lost your password?