introduction to test automation in java and php

25
Tho Q Luong Hanoi, June 28, 2014

Upload: tho-q-luong-luong

Post on 18-Nov-2014

229 views

Category:

Software


0 download

DESCRIPTION

 

TRANSCRIPT

Page 1: Introduction to test automation in java and php

Tho Q Luong

Hanoi, June 28, 2014

Page 2: Introduction to test automation in java and php

2

Assuming listeners know:

Fundamentals of OOP

Basics of Java and PHP

Convention in this talk: when saying “test”

I mean “test automation”, “automated test”

(vs. manual test)

Before Outline

Page 3: Introduction to test automation in java and php

Outline 3

• Introduction

• Testing Framework: JUnit

• Best Practice to Implement Unit Test

• FAQ

• Conclusion

Page 4: Introduction to test automation in java and php

Introduction 4

Cool things that we were learnt in the school:

1. Algorithm and programming

2. UML and design

3. Test

4. Software project management

Must utilize all of them to create a good app?

Page 5: Introduction to test automation in java and php

Introduction 5

Definition of test automation:

“Test automation is the use of special software to control

the execution of tests and the comparison of actual

outcomes with predicted outcomes”

Page 6: Introduction to test automation in java and php

6

test and me: a love story

Introduction

Page 7: Introduction to test automation in java and php

Test and me 7

Coding business services

Try my best but my code still

has serious errors

Developers in GUI layer

complain

Testers complain

And the world hates me

Q: How to let they know I

am a good developer ?

A: writing unit test

Business Service

GUI

Database

Three-tier application

Page 8: Introduction to test automation in java and php

Test and me: benefits of testing 8

Save my life

Improve product quality

Save my energy when:

Modify source code:

Maintain, upgrade

Fix bugs

Identify bugs

Avoid my silly and repetitive bugs

Page 9: Introduction to test automation in java and php

Testing Framework: JUnit

9

Page 10: Introduction to test automation in java and php

Testing Framework: JUnit 10

JUnit is an unit testing framework for Java

The most popular testing framework for Java

Ported to other languages: CPP, PHP, C#, Ruby,

Javascript … (21 languages)

Supported in IDEs: Netbeans, Eclipse

Simple and easy to use

Page 11: Introduction to test automation in java and php

Testing Framework: JUnit 11

Test Class

Test Result

Expected Outcome

Page 12: Introduction to test automation in java and php

Testing Framework: JUnit 12

Suite:

Group tests from many classes

Run test group as a single test execution

Category:

Group tests that are marked in sepecific classes

Run test group as a single test execution

Page 13: Introduction to test automation in java and php

JUnit summary 13

Keywords:

1. Assert.assertXXX()

2. @BeforeClass

3. @AfterClass

4. @Before

5. @After

6. @Test

7. Suite

8. Category

Page 14: Introduction to test automation in java and php

Best Practice

to

Implement Unit Test

14

Page 15: Introduction to test automation in java and php

Best Practice 15

06 steps:

1. Identify test class, test method

example: to test UserService and AccessControlService:

create UserServiceTest with two method:

1. testUser(): CRUD and Find

2. testAccessControl(): assign, unassign and check permission

Page 16: Introduction to test automation in java and php

Best Practice 16

06 steps:

2. Describe test

Page 17: Introduction to test automation in java and php

Best Practice 17

06 steps: 3 + 4

3. Implement test: should prefix variables by step name

4. Join test into Single Test Category and run

Page 18: Introduction to test automation in java and php

Best Practice 18

06 steps: 5 + 6

5. Create new suite or category if necessary

6. Join test into suitable suite(s) and/or category(s) and

run this suite(s) and/or category(s)

DEMO:

1. Single Test Category

2. Test Low Layer (Services)

3. Test High Layer (Controllers)

4. Load Test

----------

Page 19: Introduction to test automation in java and php

FAQ

19

Page 20: Introduction to test automation in java and php

FAQ 20

Q: what is test-driven development?

A: “is a software development process that replies on

the repetion of very short development cycle:

1. Add a test

2. Run all tests and see if the new one fails

3. Write some code

4. Run tests

5. Refactor code

And repeat”

Related to the test-first programming concepts of XP

Page 21: Introduction to test automation in java and php

FAQ 21

Q: It is already 100K LOC, with no tests. Is it over?

A: NO, this is the good time to try writing tests

Page 22: Introduction to test automation in java and php

FAQ 22

Q: what is mock object?

A: Simulate objects that mimic behavior of real objects

Used in a unit test when real object is impracticial

Q: have you ever used a mock framework in test?

A: NO

Q: what are disadvantages of writing unit tests?

A: Slow down the release time

Page 23: Introduction to test automation in java and php

FAQ 23

Q: Do good developers not need to write test?

NO, because good developers will work with more

sophisticated projects

Q: Do good products have good tests and vice

versa?

Maybe YES

Page 24: Introduction to test automation in java and php

Conclusion 24

Test Automation lengthens coder life

and improves software quality

JUnit is easy to use

Let start writing unit test to build a better life!

Page 25: Introduction to test automation in java and php

Thank you!

25