Giter Site home page Giter Site logo

xctestgen's Introduction

XCTestGen

CLI for automatic XCTest generation using OpenAI API. If you want to use this CLI, please obtain an OpenAI API Key. You can create at here.

This project uses OpenAISwift for the OpenAI API.

Github issues Github forks Github stars Github top language Github license

Installation

Execute the following command from above.

$ git clone [email protected]:NakaokaRei/XCTestGen.git
$ cd XCTestGen
$ swift build -c release
$ cp .build/release/XCTestGen /usr/local/bin/XCTestGen

Usage

Executing the command with the path of the input file and the path of the destination folder will save the unit test code in the destination folder.

$ XCTestGen $OPENAI_KEY "input file path" "output dir path"

e.g. If Sample.swift is input, SampleTests.swift will be created in the output destination.

// Sample.swift
class Sample {
    func sample1(x: Int) -> Int {
        return x + 1
    }

    func sample2(x: String) -> String {
        return x + "sample"
    }
}
// SampleTests.swift
import XCTest

class SampleTests: XCTestCase {

    func test_sample1() {
        // given
        let expectedResult = 11
        let sampleInput = 10
        let sut = Sample()

        // when
        let result = sut.sample1(x: sampleInput)

        // then
        XCTAssertEqual(result, expectedResult)
    }

    func test_sample2() {
        // given
        let expectedResult = "testsample"
        let sampleInput = "test"
        let sut = Sample()

        // when
        let result = sut.sample2(x: sampleInput)

        // then
        XCTAssertEqual(result, expectedResult)
    }
}

Help

OVERVIEW: CLI to automatically generate XCTests using ChatGPT

USAGE: xc-test-gen <key> <input> <output> [--max-tokens <max-tokens>]

ARGUMENTS:
  <key>                   API Key
  <input>                 input file path
  <output>                output dir path. do not include the trailing slash.

OPTIONS:
  -m, --max-tokens <max-tokens>
                          Maximum tokens (default: 1000)
  --version               Show the version.
  -h, --help              Show help information.

Contributors

License

MIT license. See the LICENSE file for details.

xctestgen's People

Contributors

nakaokarei avatar

Stargazers

Brady avatar Hussein Elbeheiry avatar 86 avatar  avatar gk avatar Ippo avatar Akihiro Ihara avatar k-kohey avatar Kazuya Ito avatar  avatar Taishin Miyamoto avatar  avatar

Watchers

 avatar

xctestgen's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.