Part3 : Database Testing | How To Test Schema of Database Table | Test Cases
Summary
TLDRThis video tutorial guides viewers through schema testing of database tables, a fundamental aspect of ensuring data integrity. It emphasizes the importance of understanding database design documents to identify table names, columns, data types, and constraints. The presenter shares a document outlining the 'classic models' database schema and demonstrates how to create test cases for verifying table presence, naming conventions, column counts, names, data types, sizes, nullability, and keys. Using MySQL as an example, the video shows how to execute SQL queries to validate these aspects, highlighting the process of structural testing for database schema validation.
Takeaways
- š The video discusses the process of schema testing on database tables, emphasizing the importance of understanding table structure, column details, and data types.
- š Before testing, one must refer to a database design document for table names, column names, data types, and sizes to ensure the requirements are well understood.
- š The video uses a 'classic models' database as an example to demonstrate how to set up and test a MySQL database schema.
- š A database schema document is essential as it provides detailed information about tables, their relationships, and columns, which is crucial for creating test cases.
- š The script mentions various database objects like tables, columns, keys, and constraints, and how to verify their presence and properties through testing.
- š ļø The video outlines specific test cases for checking table presence, naming conventions, number of columns, column names, data types, column sizes, nullability, and keys.
- š An Excel sheet is used to organize test cases, including test case IDs, descriptions, expected results, and status updates after execution.
- š» The execution of test cases involves connecting to the database and running SQL queries to verify the schema against the expected requirements.
- š¬ The 'information_schema.columns' table in MySQL is highlighted as a key resource for extracting metadata about table columns for testing purposes.
- š The video provides step-by-step instructions on how to execute SQL queries to test for table existence, column names, data types, column sizes, nullability, and keys.
- š The process of schema testing is iterative, requiring the same tests to be performed on all tables within a database to ensure accuracy and consistency.
Q & A
What is the purpose of schema testing in database testing?
-Schema testing is performed to verify the structure and integrity of the database. It ensures that the tables, columns, data types, sizes, and constraints are defined as per the database design document, which is crucial for maintaining data consistency and accuracy.
What are the prerequisites before starting schema testing on a database table?
-Before starting schema testing, one must know the table name, the different columns available, the data type of the columns, and the size of the columns. These details are usually available in the database design document, which serves as a reference for testing.
Can you explain the role of a database design document in schema testing?
-A database design document provides detailed information about the database schema, including the tables, their relationships, columns, data types, and sizes. It is essential for schema testing as it outlines the expected structure and constraints of the database, which testers use to create and execute test cases.
What does the term 'information schema' refer to in the context of databases?
-The 'information schema' is a collection of read-only views in a database that contain metadata about all the database's tables, columns, data types, and keys. It is used to retrieve information about the database structure and is often queried during schema testing to verify the actual database structure against the expected one.
How can you check if a specific table exists in a MySQL database?
-In MySQL, you can check if a specific table exists by using the 'SHOW TABLES' command followed by the table name. This command lists all the tables in the database, and you can verify the presence of the required table in the output.
What is the significance of checking table name conventions during schema testing?
-Checking table name conventions ensures that the table names adhere to the naming standards specified in the design document. This is important for maintaining consistency, readability, and avoiding errors due to improper naming, such as using spaces or special characters.
How do you verify the number of columns in a table as per the database design document?
-You can verify the number of columns in a table by querying the 'information schema.columns' view in MySQL. The query 'SELECT COUNT(*) FROM information_schema.columns WHERE table_name = 'your_table_name'' will return the total number of columns in the specified table, which can then be compared with the expected number from the design document.
What is the importance of testing column names, data types, and sizes in a table?
-Testing column names, data types, and sizes is crucial for ensuring that the table structure matches the design document. It verifies that each column is correctly named, has the appropriate data type to store the intended data, and has the correct size to accommodate the data within the specified limits.
Can you explain the process of checking nullability and keys associated with table columns during schema testing?
-During schema testing, you check nullability by verifying which columns allow NULL values, indicating that they can store unknown or missing data. You also check the keys associated with columns, such as primary keys, foreign keys, or unique keys, to ensure they enforce the necessary constraints and relationships as defined in the design document.
How do you structure a test case document for schema testing of database tables?
-A test case document for schema testing should include columns like Test Case ID, Description, Expected Result, Actual Result, Test Data, and Status. It should cover various test scenarios, such as checking table presence, table name conventions, column names, data types, column sizes, nullability, and keys associated with columns.
What is the difference between structural testing and other types of database testing?
-Structural testing, also known as schema testing, focuses on the physical structure of the database, such as tables, columns, and constraints. It is different from other types of testing, such as functional testing, which verifies the functionality of the database against business requirements, or performance testing, which evaluates the database's performance under load.
Outlines
š Introduction to Schema Testing on Database Tables
The speaker begins by introducing the concept of schema testing on database tables, emphasizing the importance of understanding database requirements such as table names, column details, data types, and sizes. A reference to a database design document is made, which is essential for conducting tests on database objects. The 'classic models' database is mentioned as the subject of testing, with a schema document outlining tables, their purposes, relationships, and column specifications being shared. The document serves as a guide for creating test cases to verify table presence, naming conventions, column count, names, data types, sizes, and constraints.
š Test Case Preparation for Database Tables
This paragraph delves into the specifics of preparing test cases for database tables. It discusses the need to verify table presence in the database schema, adherence to naming conventions, the correct number of columns, column names, data types, column sizes, nullability, and keys or constraints applied to columns. An example of an Excel sheet containing sample test cases is shared, with test case IDs and descriptions for checking various aspects of the database tables. The paragraph also explains how to execute SQL queries to check for table existence and naming conventions using the 'SHOW TABLES' command in MySQL.
š Executing SQL Queries for Schema Validation
The speaker provides a detailed walkthrough of executing SQL queries to validate the schema of a database. This includes checking the number of columns in a table using the 'COUNT' function on the 'information_schema.columns' table, verifying column names and data types, and ensuring column sizes match the design document. The paragraph explains how to use the 'DESCRIBE' command to get metadata about a table and how to use the 'information_schema.columns' table to extract detailed information about columns, including whether nulls are allowed and the type of keys associated with each column.
šļø Describing the 'information_schema.columns' Table
This section describes the 'information_schema.columns' table, which contains metadata about all the tables in a MySQL database. The 'DESCRIBE' command is used to display all the fields and their information, such as data types, nullability, keys, and other details. The paragraph explains how this administrator table can be used to extract information from any table in the database, which is crucial for schema validation and testing.
šļø Validating Column Names and Data Types
The speaker demonstrates how to validate column names and data types in a table using SQL queries. By selecting specific columns from the 'information_schema.columns' table, the speaker shows how to retrieve and compare column names and data types against the expected values from the database design document. The importance of matching these elements to ensure the database schema is correctly implemented is highlighted.
š Checking Column Sizes and Nullability
This paragraph focuses on verifying the size of columns and their nullability as per the database design document. The speaker explains how to execute queries to retrieve column names along with their data types and sizes, and how to compare these with the expected values. The concept of null fields as unknown values is introduced, and the speaker shows how to check which columns allow nulls using the 'information_schema.columns' table.
šļø Verifying Column Keys and Constraints
The final paragraph discusses the verification of column keys and constraints in a table. The speaker explains how to use the 'information_schema.columns' table to extract column names along with their associated keys, such as primary keys or foreign keys. The importance of understanding different types of integrity constraints in databases is mentioned, and the speaker demonstrates how to execute queries to ensure that the correct keys are associated with the columns as per the design document.
Mindmap
Keywords
š”Schema Testing
š”Database Element
š”Table
š”Column
š”Data Type
š”Size
š”Nulls
š”Keys
š”Test Cases
š”Information Schema
š”Administrator Tables
š”MySQL
Highlights
Introduction to schema testing on tables, emphasizing the importance of understanding database requirements such as table names, columns, data types, and sizes.
The necessity of referencing a database design document before conducting schema testing.
Demonstration of a database schema document for 'classic models' database, detailing tables, their purposes, and relationships.
Explanation of metadata in the 'information schema.columns' table in MySQL, which stores details about database columns.
Description of test cases for verifying table presence, naming conventions, column count, and names against the schema document.
Use of SQL queries to check the number of columns in a table and compare it with the schema document.
Verification process for column names and data types using the 'information schema.columns' table in MySQL.
Importance of checking column sizes to ensure they match the schema requirements.
Testing for null fields in tables to verify if they allow null values as per the schema design.
Verification of keys and constraints associated with table columns, such as primary keys and foreign keys.
Execution of test cases through direct database connection and running SQL queries to validate table structures.
Use of an Excel sheet to organize and document test cases, including ID, description, expected results, and actual results.
Emphasis on repeating test cases for all tables in a database to ensure comprehensive schema validation.
Explanation of 'describe' command in MySQL to display metadata of a table, including fields, types, nulls, and keys.
Guidance on updating test case status to 'passed' or 'failed' based on the execution results.
Highlighting the importance of structural testing, also known as white box testing, for direct inspection of database components.
Outlook on future videos covering testing of other database objects like stored procedures and functions.
Transcripts
hi everyone welcome you all in the today's videoĀ we are going to see how we can perform schemaĀ Ā
testing on table so table is a basic databaseĀ element in which the actual data will be storedĀ Ā
in multiple columns in the rows format so beforeĀ going to test the table of the schema of the tableĀ Ā
so first we need to know the requirement likeĀ what is the table name and what are the differentĀ Ā
columns are available and what is the data typeĀ of the columns and the size of the column soĀ Ā
these details are most of the times available inĀ database design document so that is a referenceĀ Ā
document we need to have before conducting testingĀ on the database objects now let me share a smallĀ Ā
document here and which is basically describingĀ the database schema of classic models databaseĀ Ā
so in the previous video i have shown you how toĀ set up classic models database in mysql serverĀ Ā
mysql so on the same database we are going toĀ continue the testing so this is a database schemaĀ Ā
document and basically which contains uh whatĀ are the tables are available in the databaseĀ Ā
and what's the main purpose of the table uhĀ including the description which is clearly givenĀ Ā
and this document is basically data model andĀ which is described in detail like what are theĀ Ā
different tables are available and what areĀ the relationship between the tables and whatĀ Ā
are the different columns are available so allĀ this information we can get it from the smallĀ Ā
documentation this is basically data databaseĀ schema and this is basically database modelĀ Ā
and if i just come down here so this is the actualĀ requirement which we need uh to test the tables soĀ Ā
here in this database basically we have differentĀ tables like customers products product lines andĀ Ā
orders and order details payments and employeesĀ offices and so on so these are the differentĀ Ā
tables which are available in the database nowĀ in this table again they have given some list ofĀ Ā
columns and each column is having some data typeĀ along with the size like how much data this k thisĀ Ā
column can hold so that is basically representingĀ by the size and nulls are accepting or not soĀ Ā
which is giving another column and the last columnĀ is representing the keys like on which columnĀ Ā
what type of key is applied like primaryĀ key or foreign key or check constraint orĀ Ā
multi key and so on so these are the differentĀ keys which will be there on this particularĀ Ā
column so this is basically a reference documentĀ and before conducting testing on the database andĀ Ā
similarly if i just look at each and every tableĀ is having different type of columns and data typeĀ Ā
along with the size and so on okay this is a smallĀ reference document and which contains all theĀ Ā
table information in detail so includingĀ columns data types and everything so basedĀ Ā
on this document we need to prepare our test casesĀ okay so based on this document we need to prepareĀ Ā
our test cases and currently this document isĀ having only the table information but whichĀ Ā
also includes a lot of other information relatedĀ to other objects so currently this document isĀ Ā
having only the table information what are theĀ tables are available and what is their requirementĀ Ā
so by referring this document uh we have toĀ create a test cases to test the tables okayĀ Ā
so what are the exact scenarios we can test on theĀ table so let me share a small list of test casesĀ Ā
and what are the things we need toĀ test on the table database tableĀ Ā
so first of all we need to check the tableĀ presents on the database schema so whicheverĀ Ā
database we are referring like classic modelsĀ in which the database is present or not thatĀ Ā
we need to check first and then we need to checkĀ the table name conventions so whenever you createĀ Ā
some table name so we need to follow certainĀ naming conventions and whether it is followingĀ Ā
proper naming convention or not according toĀ the requirement document and then you need toĀ Ā
check the number of columns in a table like howĀ many number of columns are there in the tableĀ Ā
as per the document we need to verify and checkĀ number of uh check column names in a table so whatĀ Ā
are all columns are available so we need to verifyĀ each and every column name which is properly givenĀ Ā
or not which is meaningful or not we need toĀ check and then we need to check the data typeĀ Ā
of columns in each table so in table let us say weĀ have a number of columns and each column is havingĀ Ā
some data type so what kind of data type they haveĀ given to that particular column we have to checkĀ Ā
as per the design document and not only theĀ data type we need to also check the sizeĀ Ā
okay so that size is also most importantĀ so check the size of the columns in a tableĀ Ā
and we need to also verify check nulls fields inĀ the table so suppose there are certain columnsĀ Ā
which will allow the null value sometimesĀ such which will not allow the null valueĀ Ā
so we need to also check those columns whateverĀ available and finally we need to also check theĀ Ā
keys that means what are the different constraintsĀ are applied on those particular columnsĀ Ā
so check we need to check the column keys in aĀ particular table so these are the different uhĀ Ā
tests which we need to do on the table level soĀ we need to prepare a proper format of document uhĀ Ā
the particular test case document likeĀ which is having all the different columnsĀ Ā
like test case id description expected actual testĀ data and so on so based on this information weĀ Ā
need to first create a test cases so let me justĀ share a small document here so now if i just lookĀ Ā
at this this is a small document which is createdĀ this excel sheet basically which contains theĀ Ā
all the test cases sample test casesĀ now here i have just covered only tableĀ Ā
and columns related test cases so what we need toĀ verify the table and columns specific to tablesĀ Ā
and columns and a different type of object weĀ will see in the upcoming series so in this videoĀ Ā
especially let us mainly focus on the table andĀ fields fields are nothing but a columns now hereĀ Ā
you can see a test case ids and uh here you canĀ see check table presence in a database schemaĀ Ā
so here how we can check how we can how we willĀ know the database uh particular table is availableĀ Ā
in the database scheme or not so first we need toĀ connect to the database and then we can execute aĀ Ā
query called show tables okay so in every databaseĀ these commands will be different slightly differĀ Ā
so we need to fetch those commands we need toĀ search for those commands particular databases andĀ Ā
here i'm following the mysql database especiallyĀ okay so shows tables so this particular commandĀ Ā
will show you all the list of tables which areĀ available in the particular database schemaĀ Ā
and then what we need to verify that we need toĀ check the table name is properly given or not soĀ Ā
table name should be displayed in the list thatĀ means what the table is existed on the databaseĀ Ā
and the same thing we are expecting here andĀ once you it is passed then we can update theĀ Ā
status here and test data is not required iĀ just given some priority to the test casesĀ Ā
and we can update the status passedĀ or failed at the time of executionĀ Ā
now check the table name convention so in theĀ first test we are just verifying the tableĀ Ā
existence or table is available or not in theĀ database schema and the second test we are justĀ Ā
checking the table name convention so wheneverĀ you give some name to the table it should be moreĀ Ā
meaningful according to the design document weĀ need to check the name is given properly or notĀ Ā
it should not be have only one single characterĀ or single letter double letters and like we shouldĀ Ā
not have any space special characters so theseĀ things we need to verify when you're checking theĀ Ā
table name convention so for that also we canĀ execute this command show tables as a queryĀ Ā
and this will give you all the tables list ofĀ tables and we can check each and every tableĀ Ā
name is properly given or not as per the decentĀ argument the table name should be a single wordĀ Ā
and table name should not contains any spaces soĀ based on the requirement we can add a more numberĀ Ā
of expectations here and this is one test so tableĀ existence we have verified and then table nameĀ Ā
name naming convention and the next one isĀ check number of columns in a table so as soon asĀ Ā
the table is available we need to check how manyĀ number of columns are there in the table as perĀ Ā
the document so for that we need to execute oneĀ query from my sql so in the my sequel there is aĀ Ā
table admin table which is available thatĀ is information underscore schema.column soĀ Ā
columns is actual table name and which isĀ available in information underscore schemaĀ Ā
a database so this is having the metadata so whatĀ is that metadata means the metadata is nothingĀ Ā
but a data about the data that means supposeĀ i have a table in the table i have a columnĀ Ā
but in that that column information i want to knowĀ like what is that name of the column what is theĀ Ā
size of the column what is the data type of theĀ column so that information will be maintainingĀ Ā
some other tables they are basically comes underĀ administrator tables so information schema dotĀ Ā
columns is administrator table in mysql databaseĀ and similarly every database different databasesĀ Ā
having different type of administrator tablesĀ and you can find all the metadata in those tablesĀ Ā
so if i execute this particular query select countĀ star as a number of columns this alias base scaleĀ Ā
i'm giving from information underscore schemaĀ dot columns where table name equal to customer soĀ Ā
whichever table you want to find or on whicheverĀ table you want to find the number of columns youĀ Ā
can specify the table name here and that willĀ give you number of columns which are present inĀ Ā
this particular table so this is a query whichĀ you have to execute on mysql and then this willĀ Ā
return the value how many total number of columnsĀ are available in the database so this is one testĀ Ā
and now the next one is check column namesĀ in the table so here what are the columnsĀ Ā
are available and what are the names are givenĀ properly or not as per the documentation we needĀ Ā
to go through so here in the documentation theyĀ clearly provided what are the column names andĀ Ā
what are the data type and size so everything isĀ clearly mentioned so accordingly we need to checkĀ Ā
so check column names in the table so for thatĀ what we can do is we can also execute this commandĀ Ā
or sql query select the column name so as iĀ said information underscore schema.columnsĀ Ā
is administrator table so which contains allĀ the metadata information so from that we canĀ Ā
extract this column data so column underscoreĀ name from information underscore schema.columnsĀ Ā
where we need to specify the table name so thisĀ particular query will return the number of columnsĀ Ā
all the columns names from the table what are allĀ columns are available from the table it will showĀ Ā
you just the column names from the table andĀ then we need to check those column names areĀ Ā
available as mentioned in the database documentĀ again so here whatever column names they haveĀ Ā
exactly mentioned the names are exactly same orĀ not we need to verify and the next test case isĀ Ā
check the data type of column so in the previousĀ test case we just verify the names of the columnsĀ Ā
now in this we need to verify the data type ofĀ the columns and for that we need to access anotherĀ Ā
column from the same table like informationĀ schema dot columns is having one more columnĀ Ā
called column underscore name data underscore typeĀ so column name along with the data type i am ableĀ Ā
to access so these two things i am just trying toĀ retrieve from the information schema dot columnsĀ Ā
table where table name equal to customers so thisĀ query will give you exactly what are the columnsĀ Ā
are available in the table and what are the dataĀ types of those particular columns so once you getĀ Ā
the data from this query so then we need to checkĀ that data along according to our documentationĀ Ā
and that is one test and the next test caseĀ check the size of the columns so there are threeĀ Ā
different cases the first case we just verifyĀ the names of the columns in the fifth test caseĀ Ā
we just verify the data type of the column nowĀ here we are checking the size of the column okayĀ Ā
suppose when i say var card and which having someĀ size like 10 15 or 20 something so we need to alsoĀ Ā
verify the size of each and every column in theĀ table or each and every field in a table so againĀ Ā
we use the same admin table information underscoreĀ schema dot columns where table name equal toĀ Ā
customer and this will give you column name i'mĀ printing column name along with the column typeĀ Ā
okay so you need to remember few number of columnsĀ here we are using a column name okay so this is aĀ Ā
column name and here we are using column nameĀ along with the data type both we are testingĀ Ā
and here we are checking column name and columnĀ type also column type in the sense what againĀ Ā
what type of column it is again data type columnĀ name and data type will be displayed that meansĀ Ā
the size of the column will be displayed and hereĀ null's fields in the table so there is anotherĀ Ā
requirement here so if i just look at this columnĀ so nulls are allowed or not no means not allowedĀ Ā
yes means allowed so we need to check thisĀ information also again for that also we have aĀ Ā
another column called e is nullable and thisĀ column is available in information schema.columnĀ Ā
so we need to capture these two column name alongĀ with the is null so this will say no or yes andĀ Ā
once you return the data no aureus then we need toĀ compare with our expected data and then we need toĀ Ā
make or pass or fail from the sameĀ table we need to access all the dataĀ Ā
and the next one check column keys in aĀ table so each and every column is sometimesĀ Ā
having some primary equal key or foreign key orĀ check constraint or whatever it is so we needĀ Ā
to verify those keys are associated with thoseĀ columns or not and that keys information alsoĀ Ā
we can extract from the same table informationĀ underscore schema.columns so this is a table nameĀ Ā
and and we need to extract uh two columnsĀ again column name and column key these areĀ Ā
the two things we are going to extract from theĀ same table and whatever the data we are gettingĀ Ā
from this query we we are again comparing withĀ our expected data as per the design so these areĀ Ā
the few test cases which we can write on the tableĀ and fields fields or mathematic columns in a tableĀ Ā
and this is basically schema validation structuralĀ testing internally we are testing the table levelĀ Ā
columns and fields and everything so that isĀ a basically uh schema testing we are basicallyĀ Ā
focusing mainly on the table schema testing so howĀ we can execute these queries so now let us see theĀ Ā
execution part so this is the design part once youĀ understand this document and we need to understandĀ Ā
all the tables what are all tables are availableĀ and what are the relationships and uh then we needĀ Ā
to analyze this data model what are the columnsĀ data type size and available so finally we need toĀ Ā
based on this document we need to create a smallĀ excel sheet like this and test cases document andĀ Ā
now we need to execute these test cases directlyĀ by connecting the database so now let me connectĀ Ā
to the database so here i already connected to myĀ mysql database and i already have a classic modelsĀ Ā
database which is already set up in previous videoĀ now if you expand this there are multiple tablesĀ Ā
are there so here whatever test cases we haveĀ written here these test cases we need to repeatĀ Ā
for all the tables and currently here i am takingĀ only one table that is a customers table and youĀ Ā
need to repeat the same test cases and you needĀ to repeat the same test cases for multiple tablesĀ Ā
whatever tables are available in your databaseĀ for all the tables you need to perform the testingĀ Ā
right but here you need to just change the tableĀ name here i have used customers table for everyĀ Ā
test so instead of customers we need to specifyĀ the other tables of the other names of the tablesĀ Ā
now let us see the execution part so let us seeĀ each and every query how it is going to executeĀ Ā
now i told you one important uh table name rightĀ especially in my sequel that is informationĀ Ā
underscore schema.columns and if i just look atĀ this table and what are the content is availableĀ Ā
in the table go to my sql and go to the sqlĀ query open this equal query and here just typeĀ Ā
describe and information schema.columns now let usĀ execute this query and see what it is uh giving soĀ Ā
now we can just see this is the administratorĀ table and which contains all metadata forĀ Ā
regarding all the tables you can just look at thisĀ this is also a table which is available in theĀ Ā
information schema this is basically administratorĀ database inside this uh when you execute this whenĀ Ā
i describe this particular table and what is theĀ describe command will do the describe commandĀ Ā
will display all the information metadata ofĀ the table like all the fields information whatĀ Ā
are the type and what is the null keys and otherĀ information will be displayed in this so now byĀ Ā
using this table by taking help of this table weĀ will extract the information from any table it canĀ Ā
be any table we can extract the information likeĀ table catalog table schema table name column nameĀ Ā
ordinal position like keys nullable data type soĀ there are so many like say column key column typesĀ Ā
collation name so these are different informationĀ will be stored in this administrator tableĀ Ā
so by taking help of this table we can getĀ any data or any information of the tableĀ Ā
which is available in our database now by takingĀ help of this particular table let's run theĀ Ā
particular code so first of all we need to connectĀ to the classic borders classic models database soĀ Ā
for that i'm using use command use classic modelsĀ so in my sequel what this command will do thisĀ Ā
command basically focus only on the myc classicĀ model because there are other databases also thereĀ Ā
so this command will say like on which databaseĀ we are going to execute your query so now it isĀ Ā
connected to the classic models database now it isĀ using classic model database and once you connectĀ Ā
it then we need to execute this query so firstĀ of all let's see our table is there or not showĀ Ā
tables is my command let me just execute showĀ tables [Music] so this particular command willĀ Ā
give you what are all tables are available in theĀ classic models database schema now let me executeĀ Ā
now you can see the customer is available as aĀ first table and totally a tables are there soĀ Ā
customer employees offices order details ordersĀ payments products product lines and products soĀ Ā
these are the tables which are available in theĀ database so customers table is already availableĀ Ā
by database so with this uh this particular testĀ is got passed you can see okay as per expectation
so actual result is what so table isĀ present we can say as per uh expectation
okay so now this is got passed let me update as aĀ past now the next one check table name conventionĀ Ā
so what we are expecting here table name shouldĀ be a single word table so table name should notĀ Ā
contains any spaces and uh this is applicableĀ for all the tables if i just look at all theĀ Ā
table names there are single word tablesĀ are there there is no spaces or there isĀ Ā
no special characters nothing so everythingĀ is fine so i can also make this test pass
right so now the next one check the numberĀ of columns in a table how we can verifyĀ Ā
the number of columns in a table so we canĀ just execute this command let me show youĀ Ā
so what is this command will say select accountĀ star as so this is basically alias because if evenĀ Ā
if you don't specify this the value will come hereĀ but if you want to give some proper column name soĀ Ā
i can just specify this is alias so count star asĀ a number of columns from and whatever the metadataĀ Ā
we want to get from the for the particular tableĀ we will able to access from information schemaĀ Ā
so select the count star as a number of columnsĀ from information scheme underscore schema.columnsĀ Ā
and where we need to specify the table nameĀ for which table you want to get informationĀ Ā
so we need to get the table name customers soĀ when you execute this particular executable ofĀ Ā
this particular statement this will give exactlyĀ how many number of columns are available insideĀ Ā
this particular table okay so select count star asĀ number of columns so this is number of columns heĀ Ā
says just a name column alias we can say and evenĀ if you're not specifying no problem it will justĀ Ā
print the value like this let me executeĀ Ā
so it will give you just like count star so justĀ if you want to give some proper alias you can sayĀ Ā
as number of columns and then you can executeĀ this query so once you executed this query so thisĀ Ā
will give you total number of columns which areĀ available in the table and then we need to compareĀ Ā
with our expected so expected is also 13 actual isĀ also 13 so then i can make my test method passedĀ Ā
this is one test and next one is check columnĀ names in the table so each column name isĀ Ā
properly given or not as per the design documentĀ we need to check so for that we need to extractĀ Ā
only column names so here instead of count starĀ we need to just specify the column next let'sĀ Ā
say select the column name this particular columnĀ name is already available in this particular tableĀ Ā
information schema.columnstable this is againĀ admin statement administration table all metadataĀ Ā
will be maintained in this so here we need toĀ specify the table name so select a column nameĀ Ā
and what this command will do this commandĀ will extract column names only column namesĀ Ā
from this particular table now let's execute thisĀ command and it will show you only column namesĀ Ā
from this table you can see customer numberĀ customer name contact last name contact firstĀ Ā
name phone address line one address line twosĀ only columns you are verifying just the columnĀ Ā
names here we are not verifying size or date typeĀ or nothing we are just verifying only the columnĀ Ā
names here so we can just look at here these areĀ the different columns it is displayed then we needĀ Ā
to compare these column names manually with ourĀ uh document so for the customer document what areĀ Ā
the column names they have given so these areĀ exactly column names which are matching withĀ Ā
the column names which are alreadyĀ available in the table so that we need toĀ Ā
compare and match and if everything is equalĀ then we can make this as a past so like this weĀ Ā
can execute this query and we can get only columnĀ name from the table and then if you want to testĀ Ā
the same thing for another table just changeĀ the table name here and that will give you theĀ Ā
number of columns in another table okay so thisĀ is a query which we need to execute to displayĀ Ā
only column names and then we can compare withĀ the as per the documentation and then we can makeĀ Ā
it is passed or failed so now the same columnsĀ are available so i'm just making this as a pastĀ Ā
and now let's go to the next one check the dataĀ type of the columns in a table so previous test weĀ Ā
have just verified only column names are availableĀ or not the names are correctly given or not but inĀ Ā
this time we have to check the data type of theĀ column so what kind of data type they have givenĀ Ā
in each and every column so for that we need toĀ execute the same query but we need to extractĀ Ā
other column let me show you this so selectĀ column name so i'm extracting column name alongĀ Ā
with the data type so data type is also one of theĀ column which is available in this particular tableĀ Ā
so column name along with the data typeĀ i want to get from this table whereĀ Ā
table name equal to customers so now whenĀ i execute this query so this will give youĀ Ā
the column names along with the data typeĀ so previously we extracted only column namesĀ Ā
but this time we are extracting column namesĀ along with the data type and again here we are notĀ Ā
extracting the size we are just extracting onlyĀ the data so according to this we need to againĀ Ā
check this data which is correct or not accordingĀ to our documentation so the same data typeĀ Ā
values are getting or not for a particular columnĀ wise we need to verify so this particular columnĀ Ā
is having inter type so again we need to checkĀ this column is having intertype then customerĀ Ā
name contact last name first name these are allĀ wirecard types so these are all wirecard typesĀ Ā
right so like this we need to compare each andĀ every column along with the data type and onceĀ Ā
everything is fine so credit limit is a decimal soĀ here also credit decimal credit limit is a decimalĀ Ā
so like this we need to compare the data typeĀ of every column so if everything is matches thenĀ Ā
we can make this test method test case alsoĀ passed this is data type validation of the columnsĀ Ā
and next one check the size of the columns soĀ we verified the names of the columns verifiedĀ Ā
the data type of the columns now we need toĀ verify the size of the column so each and everyĀ Ā
column is having a sum size let us say if you wantĀ to store the name of a person i can give 15 or 20Ā Ā
or 30 with worker type so that particular columnĀ will allow you to store only the names which areĀ Ā
uh the digits of the character so which within aĀ limit let's say when i say 15 i can store only 15Ā Ā
characters maximum right the name should havingĀ only 15 characters so that is decided by theĀ Ā
size of the column so that also we need toĀ verify so we need to execute the same query againĀ Ā
and here from the same administrator table thisĀ time we have to extract the column type not theĀ Ā
data type we have to extract the column type soĀ column name and column type so column type willĀ Ā
give you the data type along with the size nowĀ let's execute this command and you can see hereĀ Ā
so these are the different column names alongĀ with the data type and the size both have givenĀ Ā
so when i say customer number int is a data typeĀ 11 is a size and customer name varchar is a dataĀ Ā
type 50 is a size so this data exactly shouldĀ match with our documentation so exactly matchĀ Ā
with our documentation okay and this thingĀ we need to compare so here we are basicallyĀ Ā
comparing the we are checking the size of theĀ column okay these three test cases we are checkingĀ Ā
three different things in the first one we areĀ just checking the names of the column in thisĀ Ā
query we are checking the column data type andĀ in this we are verifying the size of the columnĀ Ā
as per the document is is correct or not soĀ the size of the column is perfectly fine almostĀ Ā
everything is 50 and first one is 11 last oneĀ is eleven ten comma two is a decimal and if iĀ Ā
just look at the documentation also ten commaĀ two decimal int is eleven and rest of them allĀ Ā
are fifty and postal code is a fifteen isĀ there so you can just look at here postalĀ Ā
code is a fifteen perfectly fine so in thatĀ case we can just make this test case passed
all right so now the column level validations areĀ done so there is there are two more validations weĀ Ā
need to do on the table that is check null fieldsĀ in a table null fields how we can capture the nullĀ Ā
field so if i just look at the document againĀ so here there are number of columns are thereĀ Ā
so each column is say no no means no meansĀ what that particular name will not allow youĀ Ā
nulls yes means what it will allow you nullsĀ or repetition of values are not allowedĀ Ā
so now you can see check null fields in a tableĀ basically null is nothing but unknown valueĀ Ā
okay if you don't know the value you can just makeĀ it as a null that is unknown value and later youĀ Ā
can update the value okay so if you want to knowĀ what are the columns or null allowed or not so weĀ Ā
can execute this command and all these data weĀ can extract from the administrator table whichĀ Ā
is information schema dot columns so columnĀ name along with the e is underscore nullableĀ Ā
from information schema dot columnsĀ where table name equal to customersĀ Ā
so when you execute this now you can getĀ the same thing so this particular columnĀ Ā
no is nullable no customer name is nullableĀ no contact last name is nullable noĀ Ā
okay so like this we can just verify uh theseĀ nullable fields for every column as per theĀ Ā
documentation like this and similarly finally weĀ need to verify the keys what are the differentĀ Ā
keys are associated with those columns and ifĀ i just look at here for every table there isĀ Ā
a primary key there is a multiple key here andĀ uh see here primary key and multiple keys areĀ Ā
there and some tables are having two primary keysĀ some tables are having two multiple keys like thisĀ Ā
right so now we need to verify thoseĀ keys are properly associated with theĀ Ā
columns or not so for that we have one moreĀ command here column key we need to extractĀ Ā
so execute this command so this one check theĀ null fields first right so let me execute thisĀ Ā
so this is the one we already executed thisĀ so if i just execute this this will give youĀ Ā
nullable columns so this is sameĀ thing so i can just also make it pastĀ Ā
and then check the column keys in a tableĀ so in the table we can also verify thatĀ Ā
each and every column is associated withĀ the constraint properly or not so forĀ Ā
that we can also execute this command or thisĀ particular query from information schema only soĀ Ā
column name along with the column key soĀ what is the column key representing with thisĀ Ā
representing a particular key is allocated forĀ that particular column or not so understand thisĀ Ā
we need to know what are the different constraintsĀ are available in the database all these things soĀ Ā
integrity constraints concept you have to knowĀ uh if you understand this one okay this is aĀ Ā
dependent topic so column key from informationĀ schema dot columns where table name equal toĀ Ā
customers so when i execute this query so thisĀ will give you exact what are the columns areĀ Ā
available each column is associated with the whatĀ is the column key here prime is a primary keyĀ Ā
means multiple key okay sometimes you may seeĀ check constraints sometimes you see you needĀ Ā
not null constraint like this so these are theĀ different keys you can see in this table so thisĀ Ā
is the query which we have to execute to know whatĀ are all keys are available or respective columnsĀ Ā
okay so currently we have only in this tableĀ i have only first one is a primary key customĀ Ā
customer number and sales repo saleĀ representative employee number is a multiple keyĀ Ā
okay multiple means it will allow theĀ multiple values and uh now this is a pastĀ Ā
so this is how we need to just verify the tableĀ structure basically we are mainly focusing on theĀ Ā
structure so which is becomes under structuralĀ testing structural testing and which is againĀ Ā
called as a white box testing we are checking theĀ directly table so table columns table column dataĀ Ā
type and table columns uh size of the columns theĀ data type of the columns and what are the keys areĀ Ā
associated with those columns and whether theseĀ keys are those those columns are allowing nulls orĀ Ā
not so those things we are verifying basically onĀ the table uh table component okay so these are theĀ Ā
few test cases which we can write and execute onĀ the table level so the same test we can continueĀ Ā
with the rest of the tables which are availableĀ in the database okay and uh in the next videoĀ Ā
i'll show you how we can test other type ofĀ objects like stored processor functions and so onĀ Ā
and uh that's it so that's all for this video guysĀ thanks for watching we'll see in the next video
Weitere Ƥhnliche Videos ansehen
5.0 / 5 (0 votes)