Problem Statement
Data testing of Report extractor are currently manual,we have generate the reports from RE and validate manually no other ways to do that testing fast with accuracy..
Overview
Create NUnit test project and attach into the build process of bamboo build server.Each time when any code is commit into SVN ,the continuous integration server will responsible to execute the test case.
Prerequisites for the NUnit test project:
Before executing the NUnit test project on the server, ensure that following components are exist:
- NUnit test framework
- NUnit test adapter dll (to view test results on MS Visual studio GUI)
- All the csv file of data should have in their relevant folder defined in config file.
- Access rights of folder(where build server is copied test data csv file) to insert the data into database, which is created on the fly.
- Access rights on tempdb database for create/select data comparison table since every new startup of SQL server or machine restart tempdb is losses the previously configured user permission.For that we can created SQL proc and run on SQL startup.
CREATE PROC AddTempDBOwner AS DECLARE @sql varchar(max) SELECT @sql = N'USE tempdb EXEC sp_addrolemember ''db_owner'', ''NADR\dev''' EXEC (@sql) GO EXEC sp_procoption 'AddTempDBOwner', 'startup', 'on' GO
Process of SQL testing tool integration with Bamboo
We can implement SQL testing tool with build by following steps:
NUnit test project can be created to perform testing on database from baseline data on the following are the component of the project:
Component Name
|
Description
|
|---|---|
| Config | Config.xml can be created with the information about the SQL connection setting,Input test cases,NAtrader db data,baseline data for sqltest db based on scenario like TradeCorrect/Liquidity Report. Each scenario has own configuration and based on the config information passed into setup section to create db on target server. |
| Setup (TestCaseSource) |
|
| Test method | Execute the "RunTests" on all SQLtest db defined in config.xml and setup is created successfully. |
| Datalogger | Dump all the test results into disk for future use. |
| Log manager | Log manager will be responsible for logging information in every steps for better troubleshooting if user wants. |
| TestCleanup(tear down) | This section will responsible for dropping all the created database from the target server |
Sample config File :
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<section name="SQLTests" type="Na.SQL.NUnitTests.SQLTestConfiguration.SQLTestConfigurationSection, Na.SQL.NUnitTests" allowLocation="true" allowDefinition="Everywhere"/>
</configSections>
<SQLTests>
<ConfigSetting>
<!--The reports name which needs to be changed in to natrader db created on the fly.-->
<ReportsName value="Na_Price_report,Na_Liquidity_report,Na_Liquidity_report_option"/>
<MasterConnectionSetting connectionString="server=127.0.0.1;integrated security=SSPI;database=master;Connection Timeout=500;" />
<Setups>
<!--Create db for check Liquidityreport/execta daily scenario-->
<Setup name="LIQ_TradeBust" outputFilePath="..\..\..\..\..\src\SQL\BuildResult">
<!--Description-->
<!--instances defines the number of SQL test db to be created on the fly for multiple scenario(its improvement of the EXEC-8104):-->
<ServerSetting>
<ConnectionSetting component="SQLTestDB" connectionString="server=127.0.0.1;integrated security=SSPI;database=~;Connection Timeout=500;" />
<ConnectionSetting component="NaTrader" connectionString="server=127.0.0.1;integrated security=SSPI;database=~;Connection Timeout=500;" />
<ConnectionSetting component="NaCommonDB" connectionString="server=127.0.0.1;integrated security=SSPI;database=~;Connection Timeout=500;" />
</ServerSetting>
<DataBaseCollection>
<!--Srno must be define uniquely for every DB block-->
<DB component="Natrader">
<Cab>
<File path="Output\NaTrader.cab"/>
<File path="Output\NaTrader-RG.cab"/>
</Cab>
<Data>
<object tablename="order_msgs" file="..\..\..\..\src\SQL\Na.SQL.NUnitTests.TestScripts\NaTraderDB\order_msgs.csv" />
<object tablename="order_msgs_incoming" file="..\..\..\..\src\SQL\Na.SQL.NUnitTests.TestScripts\NaTraderDB\order_msgs_incoming.csv" />
<object tablename="order_msgs1" file="..\..\..\..\src\SQL\Na.SQL.NUnitTests.TestScripts\NaTraderDB\order_msgs1.csv" />
<object tablename="order_msgs_incoming1" file="..\..\..\..\src\SQL\Na.SQL.NUnitTests.TestScripts\NaTraderDB\order_msgs_incoming1.csv" />
<object tablename="order_msgs2" file="..\..\..\..\src\SQL\Na.SQL.NUnitTests.TestScripts\NaTraderDB\order_msgs2.csv" />
<object tablename="order_msgs_incoming2" file="..\..\..\..\src\SQL\Na.SQL.NUnitTests.TestScripts\NaTraderDB\order_msgs_incoming2.csv" />
<object tablename="order_msgs3" file="..\..\..\..\src\SQL\Na.SQL.NUnitTests.TestScripts\NaTraderDB\order_msgs3.csv" />
<object tablename="order_msgs_incoming3" file="..\..\..\..\src\SQL\Na.SQL.NUnitTests.TestScripts\NaTraderDB\order_msgs_incoming3.csv" />
</Data>
</DB>
<DB component="NaCommonDB">
<Cab>
<File path="Output\NaCommonDB.cab"/>
</Cab>
<Data>
<object tablename="Common_PossibleValue_Master" file="..\..\..\..\src\SQL\Na.SQL.NUnitTests.TestScripts\NaCommonDB\Common_PossibleValue_Master.csv" />
<object tablename="Common_RG_LastMkt_Mapping" file="..\..\..\..\src\SQL\Na.SQL.NUnitTests.TestScripts\NaCommonDB\Common_RG_LastMkt_Mapping.csv" />
<object tablename="Common_RG_SymbolMapping" file="..\..\..\..\src\SQL\Na.SQL.NUnitTests.TestScripts\NaCommonDB\Common_RG_SymbolMapping.csv" />
<object tablename="Common_RG_Destinations" file="..\..\..\..\src\SQL\Na.SQL.NUnitTests.TestScripts\NaCommonDB\Common_RG_Destinations.csv" />
<object tablename="Common_RG_TierMapping" file="..\..\..\..\src\SQL\Na.SQL.NUnitTests.TestScripts\NaCommonDB\Common_RG_TierMapping.csv" />
<object tablename="Common_RG_Fee_Schedules" file="..\..\..\..\src\SQL\Na.SQL.NUnitTests.TestScripts\NaCommonDB\Common_RG_Fee_Schedules.csv" />
</Data>
</DB>
<!--Scenario must be define for each SQLTestDB component to create multiple databases Sql test db for execute Runtest.-->
<DB component="SQLTestDB" scenario="LIQ">
<Cab>
<File path="Output\RGTestingUtility.cab"/>
</Cab>
<Data>
<object tablename="InputTestData" file="..\..\..\..\src\SQL\Na.SQL.NUnitTests.TestScripts\TestCasesRG\InputTestData.csv" />
<object tablename="BaselineData" file="..\..\..\..\src\SQL\Na.SQL.NUnitTests.TestScripts\TestCasesRG\BaselineData.csv" />
</Data>
</DB>
<DB component="SQLTestDB" scenario="TradeBust">
<Cab>
<File path="Output\RGTestingUtility.cab"/>
</Cab>
<Data>
<object tablename="InputTestData" file="..\..\..\..\src\SQL\Na.SQL.NUnitTests.TestScripts\TestCasesRG\InputTestData.csv" />
<object tablename="BaselineData" file="..\..\..\..\src\SQL\Na.SQL.NUnitTests.TestScripts\TestCasesRG\BaselineData.csv" />
</Data>
</DB>
</DataBaseCollection>
</Setup>
</Setups>
</ConfigSetting>
</SQLTests>
</configuration>
|
Description about the Setup :
We can create multiple test scenario for execute test cases into single setup, like above config file have "Setup" block named LIQ which is parent container of SQLtest,but we can put multiple scenario for executing the test cases like config file have two scenario (LIQ and TradeBust) for both two separate SQLtest db installed and test against same Natrader db i.e(LIQ_TradeBustNaTrader2012).
We can also define multiple "Setup" blocks containing multiple scenarios block under the "Setups" block in config, the only difference between these two blocks are test cases and test data path are different from each other.
Database Creation logic :
For creating unique database name of NaTrader and SQLtest DB we can take the setup attribute, then under the setup>server setting and get the component name and add the 4 digit random number by cs code, so the final data base name of each component will be look like this
| Logic | DB Name |
|---|---|
| LIQ+NaTrader+1879 | LIQNaTrader1879 |
| LIQ+SQLTestDB+1879 | LIQSQLTestDB1879 |
| LIQ+NaCommonDB+1879 | LIQNaCommonDB1879 |
| Since we are using Nacommon db name in few reports like(daily,earn report) in Natrader.We don't worry about the name of NacommonDB,the test project is responsible to update dynamic NaCommondDB like "LIQNaCommonDB1879" name is concerned Natrader DB reports and execute the tests based on it. |
Structure of Unit test case
[TestFixture]
public class ThingTest
{
// Setup
// Exercise
// Verify
// Teardown
[Test]
public void TestSomething()
{
}
}
|
Steps of integration with Bamboo
- Go to Bamboo and Modify plan.
- Click on Default job and select "Task" tab.
- Add the Script task to execute nunit-console.exe by batch file.
- Provide the script file name and parameters to passed into the bat file.
- Add NUnit Test parser to parse the test result which is generated by nunit-console.exe.
- Provide the file name which needs to be parse result and display on Bamboo GUI.





