107
Yung-Chun Chang Introduction to Software Quality Assurance and Its Implementation 12/12/2016 Institute of Information Science, Academia Sinica, Taipei, Taiwan. Email: [email protected]

Introduction to software quality assurance and its implementation

Embed Size (px)

Citation preview

  • Yung-Chun Chang

    Introduction to Software Quality Assurance and Its

    Implementation

    12/12/2016

    Institute of Information Science, Academia Sinica, Taipei, Taiwan.

    Email: [email protected]

    mailto:[email protected]

  • Outline

    12/12/20162

    Motivation

    Introduction to Unit Test

    AutoTest using Junit

    White-box and Black-box Testing

    Test-driven Development (TDD)

    Integration Testing & Web UI Testing

  • 12/12/20163

  • Motivation - Salary

    12/12/20164

    Manual test Auto test

  • Motivation - Quality Assurance

    12/12/20165

  • Motivation - Debugs

    12/12/20166

  • User Guide (specification)

    12/12/20167

  • Motivation Refactoring ()

    12/12/20168

    Refactoring is a changing the

    structure of code without

    changing its behavior.

    Improving the Design of Existing Code

  • Motivation - Continuous Integration (CI)

    12/12/20169

  • Motivation - Continuous Integration (cont.)

    12/12/201610

    Version Control Server

    Test Server Alert

    Continuous

    Integration

    Development Team

    hudson-tray-tracker

    CI Server

  • Motivation - Continuous Integration (cont.)

    12/12/201611

    Test Servers

    Test Projects

  • Motivation - Continuous Integration (cont.)

    12/12/201612

  • Motivation - Test-driven Development (TDD)

    12/12/201613

  • Q & A

    Thanks for your listening

    12/12/201614

  • Yung-Chun Chang

    Introduction to Unit Test

    12/12/2016

    Institute of Information Science, Academia Sinica, Taipei, Taiwan.

    Email: [email protected]

    mailto:[email protected]

  • Why?

    12/12/201616

    @

    @

    @

  • What?

    12/12/201617

    Unit Test

  • What? (cont.)

    12/12/201618

    FIRST

    Fast

    Independent

    Repeatable

    Self-

    Validating

    Timely

    reporting

    production code

  • Where?

    12/12/201619

    (all functions?)

    ...

  • Where? (cont.)

    12/12/201620

    Test Target

    Test Target

    Test Target

    1.call

    2. evaluate

    1.call

    3. evaluatestatus changes

    Target

    1.call

    3. evaluate

    2. interact

  • Who?

    12/12/201621

    developerQA/QE

    (requirements)

  • When?

    12/12/201622

    (developing, TDD)

    feature(modifying, requirement changed)

    (bug fixing)

  • V

    12/12/201623

    (Process)

    (Verification)

    (Validation)

  • Test Cases

    12/12/201624

    SA/SD ...

    effort

  • Test Cases

    12/12/201625

  • Q & A

    Thanks for your listening

    12/12/201626

  • Yung-Chun Chang

    AutoTest using JUnit

    12/12/2016

    Institute of Information Science, Academia Sinica, Taipei, Taiwan.

    Email: [email protected]

    mailto:[email protected]

  • Environment Setting

    12/12/201628

    J2EE

    JDK

    Eclipse Neonc:\

    Name Download URL

    Eclipse-win32.zip https://goo.gl/DiR5n0

    Eclipse-win64.zip https://goo.gl/Ywouwe

  • Add JUnit Library

    12/12/201629

    > Build Path > Configure Build Path

    librariesAdd Library

    JUnitNextJUnit4Finish

  • Create a JUnit Test Case

    12/12/201630

    New->Other-> JUnit TestCase

  • Create a JUnit Test Case (cont.)

    12/12/201631

    Junitmain

    Junit @Test method

    @Test

    method test

    assert..Junit

    assertEquals(, );

    ->Run as-> JUnit Test

  • Junit

    12/12/201632

    New->Other-> JUnit TestCase

  • Junit

    12/12/201633

    @test:

    @test:

    class

    class:

  • Lets try it

    12/12/201634

  • Case Study:

    12/12/201635

  • 12/12/201636

  • 12/12/201637

    ()

  • public String getType();

    public String getTitle();

    public int getPrice();

    Product

    38

    Product

    - type: String

    - title: String

    - price: int

    + getId()

    + getType()

    + getTitle()

    + getPrice()

  • Public int searchPriceByTitle()

    Store.java

    39

    Store

    - items: Product []

    - vip: int

    - promote: int

    - discount: int

    - vipDiscount: int

    - mass: int+ init()

    + searchPricetByTitle(): int

    + setPromote(int, int, int, int)

    + getTotal()

    + getPromoteTotal()

    + addItem()

    + removeItem()

    + getItemCount()

    + getItem(int)

  • public int getTotal();

    ShoppingCart.java

    40

    ShoppingCart

    - items: Product []

    - vip: int

    - promote: int

    - discount: int

    - vipDiscount: int+ setPromote(int, int, int, int)

    + getTotal()

    + getPromoteTotal()

    + addItem()

    + removeItem()

    + getItemCount()

    + getItem(int)

    + empty()

  • 12/12/201641

    Query

    Shopping

    menu

    QueryResult

    Login

  • Web

    12/12/201642

    c:\

    EclipseWorkspace path = C:\SQA\workspace

    Name Download URL

    SQA.zip https://goo.gl/pM8Htf

  • Reset Tomcat Server

    12/12/201643

    12

    4

    3

    5

  • Run.

    12/12/201644

  • Completed!!

    12/12/201645

  • Lets getting started your first unit test

    12/12/201646

    EC2-Java Resources-src-model-Product.java

    new other - JUnit TestCase

  • Lets getting started your first unit test (cont.)

    12/12/201647

    ProductTest.java

    setUp, tearDown

    Finish

  • Lets getting started your first unit test (cont.)

    12/12/201648

  • Lets getting started your first unit test (cont.)

    12/12/201649

    Success!!!

  • Lets getting started your first unit test (cont.)

    12/12/201650

    Failure!!!

  • Add one more test

    12/12/201651

  • Test result - Error

    12/12/201652

  • Run all tests of your project

    12/12/201653

  • Q & A

    Thanks for your listening

    12/12/201654

  • Yung-Chun Chang

    White-box and Black-box Testing

    12/12/2016

    Institute of Information Science, Academia Sinica, Taipei, Taiwan.

    Email: [email protected]

    mailto:[email protected]

  • Basic Concept

    12/12/201656

    ( / ):

  • Basic Concept (cont.)

    12/12/201657

    ( / ):(Black-box)

  • Analysis of the pros and cons

    12/12/201658

    []

    []

    []

  • 12/12/201659

    (Coverage Rate)

  • (Statements Coverage

    12/12/201660

    = /

    1. int foo(int A, int B, int X) {

    2. if ((A>1) && (B==0)) {

    3. Y=A;

    4. }

    5. if ((A==2) || (X>1)) {

    6. Y=X;

    7. }

    8. return Y;

    9. }

    input Expected output

    A B X Y

    2 0 3 3

    1. int foo(int A, int B, int X) {

    2. if ((A>1) || (B==0)) {

    3. Y=0;

    4. }

    5. if ((A==2) || (X>0)) {

    6. Y=X;

    7. }

    8. return Y;

    9. }

  • (Branches/Decision Coverage)

    12/12/201661

    TrueFalse

    ((A>1) && (B==0))((A==2) || (X>1)) True False

    1. int foo(int A, int B, int X) {

    2. if ((A>1) && (B==0)) {

    3. Y=A;

    4. }

    5. if ((A==2) || (X>1)) {

    6. Y=X;

    7. }

    8. return Y;

    9. }

    Branch 1

    Branch 2

    input Expected output Branch 1 Branch 2

    A B X Y

    3 0 3 3 True True

    3 1 1 1 False False

    1. int foo(int A, int B, int X) {

    2. if ((A>2) && (B==0)) {

    3. Y=A;

    4. }

    5. if ((A==2) || (X>1)) {

    6. Y=X;

    7. }

    8. return Y;

    9. }

  • (Condition Coverage)

    12/12/201662

    True False

    ((A>1)&&(B==0))(A>1)(B==0)

    ((A==2)||(X>1))(A==2)(X>1)

    1. int foo(int A, int B, int X) {

    2. if ((A>1) && (B==0)) {

    3. Y=A;

    4. }

    5. if ((A==2) || (X>1)) {

    6. Y=X;

    7. }

    8. return Y;

    9. }

    Branch 1 Branch 2

    input Expected output Branch 1 Branch 2 Branch 3 Branch 4

    A B X Y

    2 0 3 3 True True True True

    1 1 1 1 False False False False

    Branch 3 Branch 4

  • (Multiple-condition Combination Coverage)

    12/12/201663

    ()

    4

    (1) A>1B==0 (2) A>1B!=0

    (3) A1)) {

    6. Y=X;

    7. }

    8. return Y;

    9. } ab c

    d e

    (A>1) && (B==0)

    Y=A

    (A==2) || (X>1)

    Y=X

    a-c-d

  • (All-Paths Coverage)

    12/12/201664

  • - (Basic Path)

    12/12/201665

    Sequence IF WhileDo WhileCase

    if ((x>5) && (y

  • (cont.)

    12/12/201666

    Path 1:

    Path 2:

    Path 3:

    1

    2

    3,4

    5,6,7

    true

    truefalse

    false

    1 2 3,4

    1 2 5,6,7

    1 5,6,7

  • Java Code Coverage for Eclipse

    12/12/201667

    From your Eclipse menu select Help Install New Software...

    In the Install dialog enter http://update.eclemma.org/ at the Work with field.

    Check the latest EclEmma version and press Next

    Follow the steps in the installation wizard.

    1 2

    3

    4

    Restart Eclipse

    and then you can see it.

  • Using the Coverage View

    12/12/201668

  • Coverage of ProductTest.java

    12/12/201669

    Why 88.4?

    Try to fix the failure test

  • Add a Test Case for Store.SearchPriceByTitle()

    12/12/201670

    Store -> New -> Other -> JUnit -> JUnit Test Case

    input Expected output

    Product Key price

    {("Book", "Java", 50)} Java 50

  • Coverage of Store.SearchPriceByTitle()

    12/12/201671

    StoreTest.java Coverage As Junit Test

    double click

  • Toward 100% Coverage Rate

    12/12/201672

    1

    2

    1

    2

    i > 1

  • Refactoring

    12/12/201673

  • Refactoring (cont.)

    12/12/201674

  • Refactoring (cont.)

    12/12/201675

  • Q & A

    Thanks for your listening

    12/12/201676

  • Yung-Chun Chang

    Test-Driven Development (TDD)

    12/12/2016

    Institute of Information Science, Academia Sinica, Taipei, Taiwan.

    Email: [email protected]

    mailto:[email protected]

  • Test-driven Development (TDD)

    12/12/201678

  • let's getting started

    12/12/201679

    Login.javafunctionTDD

  • RED: Write a test, watch it fail

    12/12/201680

    Add-> Other-> JUnit Test Case

  • GREEN: Write just enough code to pass the test

    12/12/201681

  • REFACTOR: Improve the code without

    changing its behavior

    12/12/201682

    The developed method cannot be used directly!!

  • REFACTOR: Improve the code without

    changing its behavior (cont.)

    12/12/201683

    loginValidation

    Customers.read()

  • REFACTOR: Improve the code without

    changing its behavior (cont.)

    12/12/201684

    Break the dependency

    customersetAttribute

  • REFACTOR: Improve the code without

    changing its behavior (cont.)

    12/12/201685

    Strategy Pattern

    ICustomers

    +getCustomer()

    +getCustomer()

    Customers

    +getCustomer()

    FakeCustomers

    Login

    Customer : ICustomers

  • REFACTOR: Improve the code without

    changing its behavior (cont.)

    12/12/201686

  • REFACTOR: Improve the code without

    changing its behavior (cont.)

    12/12/201687

  • Q & A

    Thanks for your listening

    12/12/201688

  • Yung-Chun Chang

    Integration Testing & Web UI Testing

    12/12/2016

    Institute of Information Science, Academia Sinica, Taipei, Taiwan.

    Email: [email protected]

    mailto:[email protected]

  • Integration Testing

    12/12/201690

  • Web UI Testing

    12/12/201691

    How to test multi-browsers??

  • Selenium

    12/12/201692

    Browser based Web Application testing tool

    Open Source License

    Support Mobile Testing Android / IOS

    Write Test case using Language of Java, C#, Python, Ruby.

  • Selenium IDE

    12/12/201693

    Selenium(http://www.seleniumhq.org/download/)Selenium IDE

    Firefox Selenium IDE

  • Selenium IDE (cont.)

    12/12/201694

    Selenium IDE Test Case

    Yahoo

    URLhttps://tw.yahoo.com/

    1111

    1111Show All Available commands->assertText link= 1111

  • Selenium IDE (cont.)

    12/12/201695

  • Selenium WebDriver

    12/12/201696

    Download Selenium WebDriver

    Add External JARs (all JAR files in lib & client.jar)

    selenium-java-3.0.1

    Download Selenium.zip

    https://goo.gl/Lr982F

  • Driver for different browsers

    12/12/201697

    Launching Firefox browser we need Geckodriver

    https://github.com/mozilla/geckodriver/releases

    Launching Chrome browser we need Chrome Driver

    https://sites.google.com/a/chromium.org/chromedriver

    https://github.com/mozilla/geckodriver/releaseshttps://sites.google.com/a/chromium.org/chromedriver

  • Lets start your first selenium test

    12/12/201698

    Add a Junit Test Case

  • Lets start your first selenium test (cont.)

    12/12/201699

  • Import Libraries

    12/12/2016100

    12

    3

    4

  • Run as Junit Test

    12/12/2016101

  • If you want to launch Chrome browser

    12/12/2016102

  • Refactoring

    12/12/2016103

  • Refactoring (cont.)

    12/12/2016104

  • Q & A

    Thanks for your listening

    12/12/2016105

  • 12/12/2016106

  • Reference

    12/12/2016107

    [] https://sec.openedu.tw/

    [30TDD] http://ithelp.ithome.com.tw/articles/10109845

    [] https://goo.gl/3dGeUH

    https://sec.openedu.tw/http://ithelp.ithome.com.tw/articles/10109845https://goo.gl/3dGeUH