Skip to content
This repository has been archived by the owner on Jul 31, 2022. It is now read-only.

Commit

Permalink
minitest intro
Browse files Browse the repository at this point in the history
  • Loading branch information
xinuc committed Apr 17, 2012
1 parent d3611f3 commit af30378
Showing 1 changed file with 54 additions and 5 deletions.
59 changes: 54 additions & 5 deletions Session4.md
@@ -1,12 +1,61 @@
# Session 4: Testing # Session 4: Libraries & Testing

## Unit Testing with Test::Unit



## Libraries


## Leveraging Libraries ## Leveraging Libraries
## RubyForge and RubyGems ## RubyGems & Bundler
## Packaging Programs and Libraries for Distribution ## Packaging Programs and Libraries for Distribution


## Testing

Testing merupakan aspek yang sangat penting dalam programming. Testing dapat
digunakan untuk memastikan apakah kode yang kita tulis bekerja sesuai dengan
yang kita harapkan.

Di ruby, ada banyak sekali testing framework yang tersedia.
Diantaranya: test-unit, minitest, rspec, shoulda dan lain-lain.
Pada sesi ini, kita akan membahas unit testing dengan menggunakan minitest,
yang merupakan test framework bawaan ruby (>= 1.9).

### Unit Testing with Minitest

Untuk menggunakan minitest, kita cukup me-require library tersebut dengan
`require 'minitest/autorun'` dan membuat testcase untuk mengetes kode yang
kita buat dengan assertion.

```ruby
# person.rb
class Person
def initialize(first_name, last_name)
@first_name = first_name
@last_name = last_name
end

def fullname
@first_name + " " + @last_name
end
end
```

```ruby
# person_test.rb
require './person'
require 'minitest/autorun'

class PersonTest < MiniTest::Unit::TestCase
def setup
@person = Person.new "John", "Smith"
end

def test_create_a_correct_fullname
assert_equal "John Smith", @person.fullname
end
end
```

kemudian kita jalankan dengan `ruby person_test.rb`.

## Introduction to TDD ## Introduction to TDD
## Red-Green-Refactor ## Red-Green-Refactor
## Describing a feature ## Describing a feature
Expand Down

0 comments on commit af30378

Please sign in to comment.