Автотестирование веб-сервиса с Ruby и Rspec

27
Автотестирование веб-сервиса с Ruby и Rspec Игорь Любин 1

Transcript of Автотестирование веб-сервиса с Ruby и Rspec

Page 1: Автотестирование веб-сервиса с Ruby и Rspec

1

Автотестированиевеб-сервиса с Ruby и

RspecИгорь Любин

Page 2: Автотестирование веб-сервиса с Ruby и Rspec

2

Игорь Любин Канд. физ.-мат. наук

Тестировщик с 1.12.2007

SQAdays 3, 5, 8, 9, 10!

О себе

Page 3: Автотестирование веб-сервиса с Ruby и Rspec

3

undev.ru

Page 4: Автотестирование веб-сервиса с Ruby и Rspec

4

Рассказать о своей работе На примере автоматизации веб-сервиса Получить обратную связь

Цель доклада

Page 5: Автотестирование веб-сервиса с Ruby и Rspec

5

UI

Page 6: Автотестирование веб-сервиса с Ruby и Rspec

6

Data Server

xmlDownloade

rjson Web

Постановка задачи

Page 7: Автотестирование веб-сервиса с Ruby и Rspec

7

Язык Библиотеки

Драйвер Фреймворк

Автоматизация

Из презентации А. Баранцева

Page 8: Автотестирование веб-сервиса с Ruby и Rspec

8

RubyWebrick

Iconv

Helpers Rspec

Автоматизация. Что есть?

Page 9: Автотестирование веб-сервиса с Ruby и Rspec

9

DataServerHelper

xmlDownloader

Helperjson …

Описание тестируемых сервисов

Page 10: Автотестирование веб-сервиса с Ruby и Rspec

10

DataServerHelper

xmlDownloader

Helperjson …

Запуск web-сервера

@data_server.start

WEBrick::HTTPServer.new(:DocumentRoot=>dir).start

Page 11: Автотестирование веб-сервиса с Ruby и Rspec

11

DataServerHelper

xmlDownloader

Helperjson …

Подготовка данных

XML JSON

schedule = Schedule.new(Time.now + 1.day)

Page 12: Автотестирование веб-сервиса с Ruby и Rspec

12

DataServerHelper

xmlDownloader

Helperjson …

Создание расписания

XML

@data_server.create_schedule(schedule)

Page 13: Автотестирование веб-сервиса с Ruby и Rspec

13

DataServerHelper

xmlDownloader

Helperjson …

Скачивание расписания

act_schedule = @downloader.download_schedule(schedule)

Page 14: Автотестирование веб-сервиса с Ruby и Rspec

14

DataServerHelper

xmlDownloader

Helperjson …

Проверка

JSON

act_schedule.should == schedule.expected

Page 15: Автотестирование веб-сервиса с Ruby и Rspec

15

describe "downloader" do

before :all do

@data_server = DataServerHelper.new

@downloader = DownloaderHelper.new

@data_server.start

end

before :each do

@data_server.delete_all_schedules

@downloader.clear_jobs_queue

end

it "download schedule for tomorrow" do

schedule = Schedule.new(Time.now + 1.day)

@data_server.create_schedule(schedule)

act_schedule = @downloader.download_schedule(schedule)

act_schedule.should == schedule.expected

end

after :all do

@data_server.stop

end

end

Rspec

Page 16: Автотестирование веб-сервиса с Ruby и Rspec

16

describe "downloader" do

before :all do

@data_server = DataServerHelper.new

@downloader = DownloaderHelper.new

@data_server.start

end

before :each do

@data_server.delete_all_schedules

@downloader.clear_jobs_queue

end

it "download schedule for tomorrow" do

schedule = Schedule.new(Time.now + 1.day)

@data_server.create_schedule(schedule)

act_schedule = @downloader.download_schedule(schedule)

act_schedule.should == schedule.expected

end

after :all do

@data_server.stop

end

end

Rspec

Page 17: Автотестирование веб-сервиса с Ruby и Rspec

17

describe "downloader" do

before :all do

@data_server = DataServerHelper.new

@downloader = DownloaderHelper.new

@data_server.start

end

before :each do

@data_server.delete_all_schedules

@downloader.clear_jobs_queue

end

it "download schedule for tomorrow" do

schedule = Schedule.new(Time.now + 1.day)

@data_server.create_schedule(schedule)

act_schedule = @downloader.download_schedule(schedule)

act_schedule.should == schedule.expected

end

after :all do

@data_server.stop

end

end

Rspec

Page 18: Автотестирование веб-сервиса с Ruby и Rspec

18

describe "downloader" do

before :all do

@data_server = DataServerHelper.new

@downloader = DownloaderHelper.new

@data_server.start

end

before :each do

@data_server.delete_all_schedules

@downloader.clear_jobs_queue

end

it "download schedule for tomorrow" do

schedule = Schedule.new(Time.now + 1.day)

@data_server.create_schedule(schedule)

act_schedule = @downloader.download_schedule(schedule)

act_schedule.should == schedule.expected

end

after :all do

@data_server.stop

end

end

Rspec

Page 19: Автотестирование веб-сервиса с Ruby и Rspec

19

$ rspec spec -f doc

downloader

download schedule for today

download schedule for week

not download yesterday schedule

not download schedule after 7th day

download schedule if it was updated

download schedule with different event names

Finished in 120.089 seconds

6 examples, 1 failures

Rspec отчет

Page 20: Автотестирование веб-сервиса с Ruby и Rspec

20

test

lib

spec

data

log

public

Структура проекта

Page 21: Автотестирование веб-сервиса с Ruby и Rspec

21

<?xml version="1.0" encoding="windows-1251"?><Grid> <Event>…</Event> <Event>…</Event> <Event>…</Event> <Event>…</Event> <Event>…</Event> <Event>…</Event> …</Grid>

XML расписания

Event

Iconv

Page 22: Автотестирование веб-сервиса с Ruby и Rspec

22

XML расписания<Event> <ID>33894863</ID> <DayNo> ... </DayNo> <Start>__DAY__ 07:00:00</Start> <Finish>__DAY__ 07:15:00</Finish> <Star>0</Star> <Name>Test Name</Name> <Info id="89724" type="2"> ... </Info> <Flag><ID>4</ID><Name>Инфо</Name></Flag> <Location> <ID> ... </ID> <Type>1</Type> </Location> <Gate> ... <Info>Test Description</Info> ... </Gate> <Type ... >other</Type></Event>

__DAY__

Event

Page 23: Автотестирование веб-сервиса с Ruby и Rspec

23

[ { "name": "Test Name", "id": "33894863", "beginning": "__DAY__ 07:00:00", "ending": "__DAY__ 07:15:00", "description": "Test Description", "type": "other" }, …]

JSON расписания

Event

Page 24: Автотестирование веб-сервиса с Ruby и Rspec

24

Данные Тестируем как

name, description текстовые поля

beginning - ending интервал времени

id числовое поле

Тестирование данных

Page 25: Автотестирование веб-сервиса с Ruby и Rspec

25

Нормальное название Длинное название Стандартные разделители

“ ‘ ` | / \ , ; : & < > ^ * ! ? « » Пустое название Пробелы ЧуВсТвИтЕлЬнОсТь К рЕгИсТрУ Окончания строк

^M, \n, \r Диакритические знаки

àáâãäå Плохие символы

♂ ♠ ♪ Греческий, арабский, китайский Другая кодировка Плохое выражение

“[|]’~<!--@/*$%^&#*/()?>,.*/\-->

Пример. Тестирование name

Page 26: Автотестирование веб-сервиса с Ruby и Rspec

26

1. Учить язык программирования2. Использовать готовые библиотеки3. Писать обертки4. Отделять данные от тестов5. Не забывать о «тестировании по

выходу»

Финальные тезисы

Page 27: Автотестирование веб-сервиса с Ruby и Rspec

27

Ruby Вики-учебник http://ru.wikibooks.org/wiki/Ruby Упражнения http://rubymonk.com

Rspec http://kerryb.github.com/iprug-rspec-presentation

Контакты E-mail: [email protected] Skype: igor.lyubin

Спасибо за внимание