T e s t i n g T e c h n i q u e s A p p l i e d t o V i r t D e v e l o p m e n t C l e b e r R o s a S r . S o f t w a r e E n g i n e e r T h O c t . 2 6 , 2 0 1 7
A G E N D A S o f t w a r e T e s t i n g B a s i c s • E q u i v a l e n c e P a r t i t i o n i n g • B o u n d a r y V a l u e A n a l y s i s • C o m b i n a t o r i a l T e s t i n g • A p p l y i n g t h e T h e o r y • 2
G l e n f o r d J . M y e r s ’ T r i a n g l e C h e c k T a k e s a s i n p u t : l e n g t h s o f a t r i a n g l e ’ s s i d e s • O u t p u t s t h e t r i a n g l e c l a s s i fi c a t i o n : • E q u i l a t e r a l • I s o s c e l e s • S c a l e n e • H o w h a r d c a n i t b e t o w r i t e a c o m p r e h e n s i v e s e t o f t e s t c a s e s ? • 3
T r i a n g l e C h e c k – F i r s t ( N a i v e ) V e r s i o n def triangle_check(a, b, c): def triangle_check(a, b, c): if a == b == c: if a == b == c: return "equilateral" return "equilateral" elif a != b != c: elif a != b != c: return "scalene" return "scalene" else: else: return "isoceles" return "isoceles" 4
T r i a n g l e C h e c k B a s i c T e s t C a s e s E X P E C T E D I N P U T O U T C O M E 1 , 1 , 1 E q u i l a t e r a l 2 , 2 , 3 I s o s c e l e s 3 , 4 , 5 S c a l e n e 5
T r i a n g l e C h e c k – T e s t f o r F i r s t ( N a i v e ) V e r s i o n class Triangle(Test): class Triangle(Test): def test_equilateral(self): def test_equilateral(self): self.assertEqual(triangle_check(1, 1, 1), "equilateral") self.assertEqual(triangle_check(1, 1, 1), "equilateral") def test_isosceles(self): def test_isosceles(self): self.assertEqual(triangle_check(2, 2, 3), "isosceles") self.assertEqual(triangle_check(2, 2, 3), "isosceles") def test_scalene(self): def test_scalene(self): self.assertEqual(triangle_check(3, 4, 5), "scalene") self.assertEqual(triangle_check(3, 4, 5), "scalene") 6
T r i a n g l e C h e c k - A n o t h e r B a s i c T e s t C a s e E X P E C T E D I N P U T O U T C O M E 1 , 1 , 1 E q u i l a t e r a l 2 , 2 , 3 I s o s c e l e s 2 , 3 , 2 I s o s c e l e s 3 , 4 , 5 S c a l e n e 7
T r i a n g l e C h e c k – E x t r a T e s t f o r F i r s t V e r s i o n class Triangle(Test): class Triangle(Test): def test_equilateral(self): def test_equilateral(self): self.assertEqual(triangle_check(1, 1, 1), "equilateral") self.assertEqual(triangle_check(1, 1, 1), "equilateral") def test_isosceles(self): def test_isosceles(self): self.assertEqual(triangle_check(2, 2, 3), "isosceles") self.assertEqual(triangle_check(2, 2, 3), "isosceles") self.assertEqual(triangle_check(3, 2, 3), "isosceles") self.assertEqual(triangle_check(3, 2, 3), "isosceles") def test_scalene(self): def test_scalene(self): self.assertEqual(triangle_check(3, 4, 5), "scalene") self.assertEqual(triangle_check(3, 4, 5), "scalene") 8
T r i a n g l e C h e c k E r r o r T e s t C a s e s E X P E C T E D I N P U T O U T C O M E 0 , 1 , 1 E r r o r - 1 , 1 , 1 E r r o r 1 , 1 , 2 E r r o r ( n o t i s o s c e l e s ) 1 , 2 , 3 E r r o r ( n o t s c a l e n e ) 9
T r i a n g l e C h e c k – I n v a l i d I n d i v i d u a l L e n g t h s class Triangle(Test): class Triangle(Test): ... ... def test_no_length(self): def test_no_length(self): self.assertEqual(triangle_check(0, 1, 1), "error") self.assertEqual(triangle_check(0, 1, 1), "error") self.assertEqual(triangle_check(-1, 1, 1), "error") self.assertEqual(triangle_check(-1, 1, 1), "error") 1 0
T r i a n g l e C h e c k – I n v a l i d L e n g t h s f o r a T r i a n g l e class Triangle(Test): class Triangle(Test): ... ... def test_sum_2_sides_larger_3rd(self): def test_sum_2_sides_larger_3rd(self): self.assertEqual(triangle_check(1, 1, 2), "error") self.assertEqual(triangle_check(1, 1, 2), "error") self.assertEqual(triangle_check(1, 2, 3), "error") self.assertEqual(triangle_check(1, 2, 3), "error") 1 1
T r i a n g l e C h e c k E x t e n d e d T e s t C a s e s P e r m u t a t i o n s o f l e n g t h s o r d e r • “ ( A + B ) < = C ” . v s . “ ( C + B ) < = A ” • I n p u t i s n o t a n u m b e r • G i v e m e a s i d e w i t h l e n g t h “ π ” • M o r e o r l e s s t h a n 3 i n p u t v a l u e s • A K A “ w h a t d o y o u m e a n b y t r i a n g l e s m u s t h a v e t h r e e s i d e s ? ” • 1 2
L e s s o n s f r o m a s i m p l e e x a m p l e E v e n e x p e r i e n c e d d e v e l o p e r s w i l l o n l y t h i n k o f a s u b s e t o f t h o s e t e s t c a s e s • I f t h e s o f t w a r e w e w r i t e i s n o t t h i s s i m p l e , w e s h o u l d d o b e t t e r t h a n i n t h i s e x a m p l e • C h o o s i n g g o o d i n p u t d a t a i s k e y • S o me i n p u t c a n b e n o b e t t e r t h a n o t h e r i n p u t a l r e a d y b e i n g u s e d • N o t a l l i n p u t a r e c r e a t e d e q u a l , s o m e w i l l h a v e a b e t t e r s h o t a t fi n d i n g i s s u e s • 1 3
E q u i v a l e n c e P a r t i t i o n i n g D o n ’ t l e t t h e n a m e s c a r e y o u • T h i n k o f g r o u p s o f i n p u t t h a t s h o u l d g e n e r a t e s i m i l a r o u t c o m e • A g o o d p i c k i s w o r t h a t l e a s t o t h e r t w o i n d i v i d u a l i n p u t s • I t u s u a l l y t e l l s u s a b o u t w h a t w o u l d h a p p e n ( e r r o r s ? ) w h e n v a l u e s a b o v e o r b e y o n d i t s e l f w o u l d b e • u s e d 1 4
I d e n t i f y i n g I n p u t T y p e s a n d E q u i v a l e n t C l a s s e s // snippets from qemu/hw/acpi/cpu_hotplug.c // snippets from qemu/hw/acpi/cpu_hotplug.c /* The current AML generator can cover the APIC ID range [0..255], /* The current AML generator can cover the APIC ID range [0..255], * inclusive, for VCPU hotplug. */ * inclusive, for VCPU hotplug. */ QEMU_BUILD_BUG_ON(ACPI_CPU_HOTPLUG_ID_LIMIT > 256); QEMU_BUILD_BUG_ON(ACPI_CPU_HOTPLUG_ID_LIMIT > 256); ... ... if (pcms->apic_id_limit > ACPI_CPU_HOTPLUG_ID_LIMIT) { if (pcms->apic_id_limit > ACPI_CPU_HOTPLUG_ID_LIMIT) { error_report("max_cpus is too large. APIC ID of last CPU is %u", error_report("max_cpus is too large. APIC ID of last CPU is %u", pcms->apic_id_limit - 1); pcms->apic_id_limit - 1); exit(1); exit(1); } } 1 5
I n p u t T y p e s a n d C l a s s e s N u m b e r o f C P U s I N V A L I D V A L I D I N V A L I D < = 0 1 . . 2 5 6 > = 2 5 7 C P U I D s I N V A L I D V A L I D I N V A L I D < = - 1 0 . . 2 5 5 > = 2 5 6 1 6
B o u n d a r y A n a l y s i s A l s o n o t s c a r y • W h e n i n p u t c l a s s e s a r e o r d e r e d , y o u c a n e a s i l y s p o t t h e m • T h e s e v a l u e s a r e u s u a l l y v e r y g o o d b e t s f o r t e s t s • 1 7
B o u n d a r y V a l u e s N u m b e r o f C P U s I N V A L I D V A L I D I N V A L I D 0 1 2 5 6 2 5 7 C P U I D s I N V A L I D V A L I D I N V A L I D - 1 0 2 5 5 2 5 6 1 8
Recommend
More recommend