SlideShare a Scribd company logo
Niepraktycznie i nieskładnie

o Test Driven Development




   Adam Przybyła <adam@ertel.com.pl>

       (Creative Commons cc-by-nd)

  Mikstura 2 Lateral Thinking - Rybnik 2013
Cykl życia
[root@synergia TDD_ANTLR]# cat test_mikstura.py
#! /usr/bin/python
import unittest

class test_moj(unittest.TestCase):
   def test_test(self):
       self.assertTrue(False)

if __name__ == '__main__':
    unittest.main()
[root@synergia TDD_ANTLR]#
[root@synergia TDD_ANTLR]# ./test_mikstura.py
F
==================================================
====================
FAIL: test_test (__main__.test_moj)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "./test_mikstura.py", line 6, in test_test
   self.assertTrue(False)
AssertionError

----------------------------------------------------------------------
Ran 1 test in 0.000s

FAILED (failures=1)
[root@synergia TDD_ANTLR]#
[root@synergia TDD_ANTLR]# cat test_mikstura.py
#! /usr/bin/python
import unittest

class test_moj(unittest.TestCase):
   def test_test(self):
       self.assertTrue(True)

if __name__ == '__main__':
    unittest.main()
[root@synergia TDD_ANTLR]#
[root@synergia TDD_ANTLR]# ./test_mikstura.py
.
----------------------------------------------------------------------
Ran 1 test in 0.000s

OK
[root@synergia TDD_ANTLR]#
#!/usr/bin/python
import unittest
import antlr3
from CSVLexer import CSVLexer
from CSVParser import CSVParser
class test_csv(unittest.TestCase):
     def setUp(self):
           pass

    def test_test(self):
         self.assertTrue(True)

    def test_lf(self):
         parser=parserek("n")
         wynik=parser.line()
         self.assertFalse(wynik)

    def test_crlf(self):
         parser=parserek("rn")
         wynik=parser.line()
         self.assertFalse(wynik)

    #@unittest.skip("omijam test")
    def test_red(self):
         parser=parserek("red")
         wynik=parser.pole()
         self.assertEqual(wynik,"red")
grammar CSV;
Options { language=Python; }
@header {
def test1(s): print "test"
}
line returns [wynik]
scope { wynik2 }
@init { wynik =[]; $line::wynik2=[]; }
: ( (NEWLINE) => NEWLINE
 | ( p1=pole {wynik.append(p1) } ( COMMA p1=pole {wynik.append(p1) } )* NEWLINE ) )
{ wynik=$line::wynik2};

COMMA : ( ' '* ',' ' '*) ;

pole returns [wynik1]
@init {
wynik1=""
try:
   wyn=$line::wynik2
except IndexError:
   wyn=[]
}
     : ( p=ZNAWIASEM { wynik1 = $p.text;}
     | p=BEZNAWIASU { wynik1 = $p.text;}
     | //nic
     ) {wyn.append(wynik1)};
NEWLINE : 'r'? 'n';

ZNAWIASEM : ('"' ( options {greedy=false;}: . )+ '"')+
   {txt = self.getText().strip('"').replace('""','"');self.setText(txt)};

BEZNAWIASU          : ~('r' | 'n' | ',' | ' ' | '"')+;
#! /usr/bin/python
# -*- coding: UTF-8 -*-
import unittest
from analizator import *
from pobieracz import *
from TDDczysciciel import Lexer
import pobieracz,analizator,warstwa_leksykalna,codecs,TDDczysciciel
class testy_pobierania(unittest.TestCase):
      def setUp(self):
           pass

    def test_dziala(self):
         self.assertTrue(True)

    def test_nazwy(self):
         self.assertTrue(nazwa_ma_ip("dns.ertel.com.pl"))

    def test_zlej_nazwy(self):
         self.assertFalse(nazwa_ma_ip("dns-45.ertel.com.pl"))

    def test_pinga_dziala(self):
         self.assertTrue(nazwa_odp_na_ping('127.0.0.1'))

    def test_pinga_niedziala(self):
         self.assertFalse(nazwa_odp_na_ping('224.0.0.0'))
Lateral Thinking


●   Wikinomia
●   Wikipedia
●   Wolna kultura
●   Falsyfikacja jako metoda naukowa i metoda testów
Pytania/pomysły?

More Related Content

PDF
PHP Profiling
PDF
07 4 for반복문
ODP
C++14 reflections
PDF
Java script.trend(spec)
PDF
Testování prakticky
PDF
An introduction to functional programming with Go [redux]
DOCX
Convert bilangan
PDF
[C++ Korea] Effective Modern C++ Study, Item 27, 29 - 30
PHP Profiling
07 4 for반복문
C++14 reflections
Java script.trend(spec)
Testování prakticky
An introduction to functional programming with Go [redux]
Convert bilangan
[C++ Korea] Effective Modern C++ Study, Item 27, 29 - 30

What's hot (19)

DOCX
ODP
Антон Полухин. C++17
PPTX
The Flavor of TypeScript
PDF
PDF
Тененёв Анатолий, Boost.Asio в алгоритмической торговле
PPTX
Алексей Кутумов, C++ без исключений, часть 3
PDF
Menu orastat.c
PDF
Rambler.iOS #8: Чистые unit-тесты
TXT
Suma de n numeros
PDF
BABELで、ES2015(ES6)を学ぼう!
PPTX
Clang-tidy: путешествие внутрь AST C++
PDF
数式を構文解析した話
PPTX
OpenResty/Lua 70+ Advanced Programming Skills and Optimization tips
KEY
JavaScript Tips
ZIP
変態的PHPフレームワーク rhaco
DOCX
Propuesta..sujei
PPTX
JavaScript Assíncrono
PPTX
Understanding Python decorators
Антон Полухин. C++17
The Flavor of TypeScript
Тененёв Анатолий, Boost.Asio в алгоритмической торговле
Алексей Кутумов, C++ без исключений, часть 3
Menu orastat.c
Rambler.iOS #8: Чистые unit-тесты
Suma de n numeros
BABELで、ES2015(ES6)を学ぼう!
Clang-tidy: путешествие внутрь AST C++
数式を構文解析した話
OpenResty/Lua 70+ Advanced Programming Skills and Optimization tips
JavaScript Tips
変態的PHPフレームワーク rhaco
Propuesta..sujei
JavaScript Assíncrono
Understanding Python decorators
Ad

More from Adam Przybyła (7)

PDF
NocInformatyka2022.pdf
PDF
Mission ImpAnsible - NSM at (RobotFrame)work
ODP
Koniec testowania na sposób “testerski”. Zmiana paradygmatu testowania oprogr...
ODP
Aby wąż giętki robił to co wymyśli głowa, czyli słów kilka o analizie leksyk...
ODP
SELinux, czyli zero-zero-day exploits - DWO 2013
ODP
Humanista w twoim linuksie
ODP
Open Source i nowe technologie, czyli trochę o systemach o dużej niezawodności
NocInformatyka2022.pdf
Mission ImpAnsible - NSM at (RobotFrame)work
Koniec testowania na sposób “testerski”. Zmiana paradygmatu testowania oprogr...
Aby wąż giętki robił to co wymyśli głowa, czyli słów kilka o analizie leksyk...
SELinux, czyli zero-zero-day exploits - DWO 2013
Humanista w twoim linuksie
Open Source i nowe technologie, czyli trochę o systemach o dużej niezawodności
Ad

Mikstura it2013

  • 1. Niepraktycznie i nieskładnie o Test Driven Development Adam Przybyła <adam@ertel.com.pl> (Creative Commons cc-by-nd) Mikstura 2 Lateral Thinking - Rybnik 2013
  • 3. [root@synergia TDD_ANTLR]# cat test_mikstura.py #! /usr/bin/python import unittest class test_moj(unittest.TestCase): def test_test(self): self.assertTrue(False) if __name__ == '__main__': unittest.main() [root@synergia TDD_ANTLR]#
  • 4. [root@synergia TDD_ANTLR]# ./test_mikstura.py F ================================================== ==================== FAIL: test_test (__main__.test_moj) ---------------------------------------------------------------------- Traceback (most recent call last): File "./test_mikstura.py", line 6, in test_test self.assertTrue(False) AssertionError ---------------------------------------------------------------------- Ran 1 test in 0.000s FAILED (failures=1) [root@synergia TDD_ANTLR]#
  • 5. [root@synergia TDD_ANTLR]# cat test_mikstura.py #! /usr/bin/python import unittest class test_moj(unittest.TestCase): def test_test(self): self.assertTrue(True) if __name__ == '__main__': unittest.main() [root@synergia TDD_ANTLR]#
  • 7. #!/usr/bin/python import unittest import antlr3 from CSVLexer import CSVLexer from CSVParser import CSVParser class test_csv(unittest.TestCase): def setUp(self): pass def test_test(self): self.assertTrue(True) def test_lf(self): parser=parserek("n") wynik=parser.line() self.assertFalse(wynik) def test_crlf(self): parser=parserek("rn") wynik=parser.line() self.assertFalse(wynik) #@unittest.skip("omijam test") def test_red(self): parser=parserek("red") wynik=parser.pole() self.assertEqual(wynik,"red")
  • 8. grammar CSV; Options { language=Python; } @header { def test1(s): print "test" } line returns [wynik] scope { wynik2 } @init { wynik =[]; $line::wynik2=[]; } : ( (NEWLINE) => NEWLINE | ( p1=pole {wynik.append(p1) } ( COMMA p1=pole {wynik.append(p1) } )* NEWLINE ) ) { wynik=$line::wynik2}; COMMA : ( ' '* ',' ' '*) ; pole returns [wynik1] @init { wynik1="" try: wyn=$line::wynik2 except IndexError: wyn=[] } : ( p=ZNAWIASEM { wynik1 = $p.text;} | p=BEZNAWIASU { wynik1 = $p.text;} | //nic ) {wyn.append(wynik1)}; NEWLINE : 'r'? 'n'; ZNAWIASEM : ('"' ( options {greedy=false;}: . )+ '"')+ {txt = self.getText().strip('"').replace('""','"');self.setText(txt)}; BEZNAWIASU : ~('r' | 'n' | ',' | ' ' | '"')+;
  • 9. #! /usr/bin/python # -*- coding: UTF-8 -*- import unittest from analizator import * from pobieracz import * from TDDczysciciel import Lexer import pobieracz,analizator,warstwa_leksykalna,codecs,TDDczysciciel class testy_pobierania(unittest.TestCase): def setUp(self): pass def test_dziala(self): self.assertTrue(True) def test_nazwy(self): self.assertTrue(nazwa_ma_ip("dns.ertel.com.pl")) def test_zlej_nazwy(self): self.assertFalse(nazwa_ma_ip("dns-45.ertel.com.pl")) def test_pinga_dziala(self): self.assertTrue(nazwa_odp_na_ping('127.0.0.1')) def test_pinga_niedziala(self): self.assertFalse(nazwa_odp_na_ping('224.0.0.0'))
  • 10. Lateral Thinking ● Wikinomia ● Wikipedia ● Wolna kultura ● Falsyfikacja jako metoda naukowa i metoda testów