Skip to content

whatasame-labs/xunit-tdd

Folders and files

NameName
Last commit message
Last commit date

Latest commit

9126a24 · Dec 10, 2023

History

28 Commits
Dec 10, 2023
Nov 29, 2023
Dec 10, 2023

Repository files navigation

xUnit TDD

This project is a TDD implementation of the xUnit testing framework using plain Java.

How to run

You can simply run the test and see the result by running main method in src/test/XUnitTest.java.

Supported features

This framework supports following features:

  • Run testable method
    • Support annotation based test
    • Throw exception if test method is not found
  • Run setUp() before testable method
    • Must be run before each testable method
  • Run tearDown() after testable method
    • Must be run even if the testable method fails
  • Collect testable results
    • Collect failed test method names and causes.
  • Run TestSuite a collection of testable cases and testable suites
    • Collect testable cases
    • Collect testable suites

Introduction

What is different from JUnit?

JUnit create test class at once and run all test methods. But this project create each instance for running each test. So in this case, you can run test class separately, for example, you don't have to care about that field value is changed by others and affect other test method. But it is not good for performance and doesn't use properly setUp() and tearDown() which is designed for invoking before and after each test method.

Class diagram

Loading
---
title: Core classes 
---
classDiagram
    class Testable {
        <<interface>>
        +run(TestResult testResult) void
    }
    Testable <|.. TestCase
    Testable <|.. TestSuite
    Testable <--* TestSuite
    class TestCase {
        -String testMethodName
        +TestCase(String testMethodName)
        +setUp() void
        +tearDown() void
        +run(TestResult testResut) void
    }

    class TestSuite {
        -Set~Testable~ tests
        +TestSuite()
        +TestSuite(Class~TestCase~ tests)
        +run(TestResult testResult) void
        +add(Testable testable) void
    }

Create your test class like JUnit inheriting TestCase class. For instance, it is implemented as WasRun class in this project.

Loading
---
title: Example test class
---
classDiagram
    class TestCase {
        -String testMethodName
        +TestCase(String testMethodName)
        +setUp() void
        +tearDown() void
        +run(TestResult testResut) void
    }
    TestCase <|-- WasRun
    class WasRun {
        +WasRun(String testMethodName)
        +testMethod() void
        +testBrokenMethod() void
    }

The testMethod() and testBrokenMethod() of WasRun can be to test. You can specify the test method name with the testMethodName parameter of the TestCase constructor. Then run() method will run the test method and collect test result.

Implementation environment

Java 17

References

About

xUnit testing framework using Java

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages