Skip to content
forked from elliotchance/dandy

The handy, dandy test generation tool for Go.

Notifications You must be signed in to change notification settings

DualSpark/dandy

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Automatically generate tests from your Go source code.

package main

func Sign(x int) int {
  if x < 0 {
    return 1
  }
  if x > 0 {
    return 2
  }

  return 3
}
go run dandy.go -- myfile.go
func TestSignXIsLessThan0(t *testing.T) {
	result := Sign(-1)
	if result != 1 {
		t.Error("Failed")
	}
}

func TestSignXIsGreaterThan0(t *testing.T) {
	result := Sign(1)
	if result != 2 {
		t.Error("Failed")
	}
}

func TestSign(t *testing.T) {
	result := Sign(0)
	if result != 3 {
		t.Error("Failed")
	}
}

The tests are rendered from the intermediate JSON format that provides information on individual paths, steps taken, input and return values:

{
  "Functions": {
    "Sign": {
      "Type": "int",
      "Args": {
        "x": "int"
      },
      "Paths": {
        "": {
          "Steps": [
            "4: if x \u003c 0 {",
            "7: if x \u003e 0 {",
            "11: return"
          ],
          "Params": {
            "x": 0
          },
          "Result": 3
        },
        "XIsGreaterThan0": {
          "Steps": [
            "4: if x \u003c 0 {",
            "7: if x \u003e 0 {",
            "8: return"
          ],
          "Params": {
            "x": 1
          },
          "Result": 2
        },
        "XIsLessThan0": {
          "Steps": [
            "4: if x \u003c 0 {",
            "5: return"
          ],
          "Params": {
            "x": -1
          },
          "Result": 1
        }
      }
    }
  }
}

About

The handy, dandy test generation tool for Go.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Go 100.0%