introduction to test automation in java and php

Post on 18-Nov-2014

229 Views

Category:

Software

0 Downloads

Preview:

Click to see full reader

DESCRIPTION

 

TRANSCRIPT

Tho Q Luong

Hanoi, June 28, 2014

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

Outline 3

• Introduction

• Testing Framework: JUnit

• Best Practice to Implement Unit Test

• FAQ

• Conclusion

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?

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”

6

test and me: a love story

Introduction

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

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

Testing Framework: JUnit

9

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

Testing Framework: JUnit 11

Test Class

Test Result

Expected Outcome

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

JUnit summary 13

Keywords:

1. Assert.assertXXX()

2. @BeforeClass

3. @AfterClass

4. @Before

5. @After

6. @Test

7. Suite

8. Category

Best Practice

to

Implement Unit Test

14

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

Best Practice 16

06 steps:

2. Describe test

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

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

----------

FAQ

19

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

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

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

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

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!

Thank you!

25

top related