Upgrade to Pro — share decks privately, control downloads, hide ads and more …

A New Testing Framework Rgot

ksss
December 12, 2015

A New Testing Framework Rgot

Speech of RubyKaigi2015 LT

ksss

December 12, 2015
Tweet

More Decks by ksss

Other Decks in Programming

Transcript

  1. A New Testing
    Framework Rgot
    ksss
    RubyKaigi2015

    View full-size slide

  2. !
    "
    ksss
    _ksss_

    View full-size slide

  3. A New Testing Framework
    was born …

    View full-size slide

  4. Rgot
    Ruby
    +
    Golang Testing
    ksss/rgot
    !

    View full-size slide

  5. $ gem i rgot
    ksss/rgot
    !
    ruby 2.0 ʙ

    View full-size slide

  6. !?
    ksss/rgot
    !

    View full-size slide

  7. Again?
    ksss/rgot
    !

    View full-size slide

  8. Do We
    Have to
    Learning New
    Things?
    ksss/rgot
    !

    View full-size slide

  9. Rgot is
    Translation
    from
    Golang Testing
    to Ruby
    ksss/rgot
    !

    View full-size slide

  10. Incidentally
    You Can Learn
    Golang Testing!
    ksss/rgot
    !

    View full-size slide

  11. Golang
    ksss/rgot
    !
    package foo_test
    func TestFooBar(t *testing.T) {
    if 3 != (1 + 2) {
    t.Error("failed")
    }
    }

    View full-size slide

  12. Rgot
    ksss/rgot
    !
    module FooTest
    def test_foo(t)
    if 3 != (1 + 2)
    t.error("failed")
    end
    end
    end

    View full-size slide

  13. Golang-ish
    ksss/rgot
    !

    View full-size slide

  14. Golang
    ksss/rgot
    !
    $ go test -v
    === RUN TestFoo
    --- PASS: TestFoo (1.01s)
    === RUN TestBar
    --- PASS: TestBar (1.00s)
    === RUN TestBaz
    --- PASS: TestBaz (1.01s)
    PASS
    ok ksss/gotest 3.017s

    View full-size slide

  15. Rgot
    ksss/rgot
    !
    $ rgot -v
    === RUN test_foo
    --- PASS: test_foo (1.01s)
    === RUN test_bar
    --- PASS: test_bar (1.00s)
    === RUN test_baz
    --- PASS: test_baz (1.01s)
    PASS
    ok RgotTest 3.042s

    View full-size slide

  16. Golang
    ksss/rgot
    !
    package foo_test
    func BenchmarkQux(b *testing.B) {
    for i := 0; i < b.N; i++ {
    foo.Qux()
    }
    }

    View full-size slide

  17. Rgot
    ksss/rgot
    !
    module FooTest
    def benchmark_qux(b)
    i = 0
    while i < b.n
    Foo.qux
    i += 1
    end
    end
    end

    View full-size slide

  18. Golang
    ksss/rgot
    !
    package pow_test
    func BenchmarkPow(b *testing.B) {
    b.RunParallel(func(pb *testing.PB) {
    for pb.Next() {
    math.Pow(1000.0, 1000.0)
    }
    })
    }

    View full-size slide

  19. Rgot
    ksss/rgot
    !
    module PowTest
    def benchmark_pow(b)
    b.run_parallel do |pb|
    while pb.next
    1000.0 ** 1000.0
    end
    end
    end
    end

    View full-size slide

  20. Golang
    ksss/rgot
    !
    $ go test -bench . -cpu 2,4
    PASS
    BenchmarkPow-2 100000000 22.3 ns/op
    BenchmarkPow-4 100000000 12.5 ns/op
    ok github.com/pow_test 3.522s
    GOMAXPROCS

    View full-size slide

  21. Rgot
    ksss/rgot
    !
    $ rgot --bench . --cpu 2,4 --thread 2,4
    PASS
    benchmark_pow-2(2) 25600000 74 ns/op
    benchmark_pow-2(4) 81920000 74 ns/op
    benchmark_pow-4(2) 81920000 39 ns/op
    benchmark_pow-4(4) 40960000 40 ns/op
    ok PowTest 13.603s
    process thread

    View full-size slide

  22. Golang
    ksss/rgot
    !
    package foo_test
    func ExampleFoo {
    fmt.Println(foo.Say())
    // Output:
    // foo
    }

    View full-size slide

  23. Rgot
    ksss/rgot
    !
    module FooTest
    def example_foo
    puts Foo.say
    # Output:
    # foo
    end
    end

    View full-size slide

  24. Golang
    ksss/rgot
    !
    $ go test -v
    === RUN ExampleFoo
    --- FAIL: ExampleFoo (0.00s)
    got:
    bar
    want:
    foo
    FAIL
    exit status 1
    FAILgithub.com/ksss/gotest 0.005s

    View full-size slide

  25. Rgot
    ksss/rgot
    !
    $ rgot -v
    === RUN example_foo
    --- FAIL: example_foo (0.00s)
    got:
    bar
    want:
    foo
    FAIL
    exit status 1
    FAILRgotTest 0.001s

    View full-size slide

  26. Thinking
    ksss/rgot
    !

    View full-size slide

  27. Diversity
    ksss/rgot
    !

    View full-size slide

  28. Testing before Benchmark
    ksss/rgot
    !

    View full-size slide

  29. Testable Sample Code
    ksss/rgot
    !

    View full-size slide

  30. Not Need
    /test or /spec
    Dir
    ksss/rgot
    !

    View full-size slide

  31. Short Class Name
    testing.M => Rgot::M
    testing.T => Rgot::T
    testing.B => Rgot::B
    ksss/rgot
    !

    View full-size slide

  32. Zero Assert
    ksss/rgot
    !

    View full-size slide

  33. t.error()
    ksss/rgot
    !

    View full-size slide

  34. More Thinking
    ksss/rgot
    !

    View full-size slide

  35. Assert Oriented
    v.s.
    Error log Oriented
    ksss/rgot
    !

    View full-size slide

  36. Assert Oriented
    case
    ksss/rgot
    !
    mimitest, test-unit, rspec, etc…

    View full-size slide

  37. case
    ksss/rgot
    !
    Error log Oriented

    View full-size slide

  38. Error
    Report
    is
    Important
    ksss/rgot
    !

    View full-size slide

  39. Precise errors are
    particularly important
    when the programmer
    seeing the errors is not
    familiar with the code.
    #https://golang.org/doc/faq#assertions
    ksss/rgot
    !

    View full-size slide

  40. Words
    ksss/rgot
    !

    View full-size slide

  41. Words
    - assert
    - should
    - expect
    - must
    minitest, test-unit, rspec, …
    ksss/rgot
    !

    View full-size slide

  42. Words
    - want
    - got
    - failed
    - invalid
    Golang testing package
    ksss/rgot
    !

    View full-size slide

  43. Words (hypothesis)
    minitest, test_unit, rspec,…
    Golang testing package
    Hard
    Soft
    ksss/rgot
    !

    View full-size slide