Giter VIP home page Giter VIP logo

unit-test's Introduction

TestNG

We have two method to test, in both method we use TestNG DataProvider ( @DataProvider(name = "name-data-provider") ) to pass the parameters in the test function, because we want to run the same test with multiple values (DDT)

Login

login

We need two parameters to test above method: user and pass

DB

DB

Test case:

  • Test loginUser with valid value valid

We use assertNotNull() to check method checkLogin()

Expected: checkLogin() return value that not null, that mean user is existed

Actual: as we can see in DB two user is existed

Result: We have green

Green

  • Test loginUser with invalid value invalid

We use assertNull() to check method checkLogin()

Expected: checkLogin() return value that null, that mean user is not existed

Actual: in DB we can see two user is not existed

Result:

Green1

In conclusion, the purpose of checkLogin() is to authenticate who the user is allowed to access to the system, after 2 test cases we have already tested 7 values that may be a user can enter, thus the behavior of checkLogin() method is matched with the expected

================================================================

Insert

Insert

We need 5 parameters to test above method: userId, fullName, password, roleId, status

In this method, we use DataProviders with method as a Parameter

Import Required: import java.lang.reflect.Method

switch

Test case:

  • Test insertUser with valid value: valid

We use assertEquals() to check method Insert()

Expected: Insert() return true

Actual: true

Result:

Rresult-val

  • Test insertUser with invalid value:

In this test:

  • Insert very long userId that break data type nvarchar(50) in DB
  • Insert existed user into DB Invalid

We use assertEquals() to check method Insert()

Expected: Insert() return false, because userId is too long and userId is existed

Actual: false, cant insert into DB

Result:

resutl-inval

In conclusion, Insert () aims to insert a new user into the system. In this test, we already checked 4 values, 2 valid, 2 invalids, and see the behavior of Insert() method is matched with the expected

In comparison after testing two methods:

  • checkLogin() method we use two Dataprovider for two tests (1)
  • Insert() method we use just one Dataprovider for all tests (2) and if any method is added, we just need to add two lines:
    • case "method" :
    • return statement.

=> to optimize we recommend use approach (2) instead of (1).

unit-test's People

Contributors

ninehnineh avatar chinhtc98 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.