zoukankan      html  css  js  c++  java
  • 使用ORAYLIS BI.Quality基于Ms的BI数据测试

    ORAYLIS BI.Quality是一个开源项目,对BI解决方案提供一种简单的测试方案。它是基于NUnit并支持多种测试方法。以下示例是2010.3.12Release v1.0版本。

      首先,需要下载安装NUnit,然后安装完成后,打到相应的目录,有一个Lib文件夹,找到里面的BI.Quality.dll。这个是已经Bulid好的了。有两种方法来测试,

    一种是用NUnit GUI,打开BI.Quality.dll,然后Run…. 它会自动加载Queries文件夹下的Files,这些文件包括三种类型,xml是配制文件,sql是用来存储具体查询语句,rslt是结果集文件(这个文件是自动生成,可以删除)。我们打看可以看到是DataSet的XML数据。

      另一个文件夹Connections,是配制连接字符串。分别对应是OLTP,OLAP,MDX的connection.也是基于XML的。内容像这样:

       1:  <Connection>
       2:    <Name>MDX-AdventureWorks</Name>
       3:    <ConnectionString>
       4:      Provider=MSOLAP.4;
       5:      Data Source=.;
       6:      Integrated Security=SSPI;
       7:      Initial Catalog=Adventure Works DW;
       8:    </ConnectionString>
       9:  </Connection>

      下面是一个MDX语句的文件内容:

       1:  select 
       2:  non empty
       3:  [Measures].[Internet Sales Amount] on columns,
       4:  non empty
       5:  [Date].[Calendar].[Calendar Quarter].Members on rows 
       6:  from
       7:  [Adventure Works]
       8:  CELL PROPERTIES VALUE;

      

      然后我们来看下要对比查询DW T-sql 语句于另一个文件中:

       1:  select
       2:    'CY ' + cast(dd.CalendarYear as nvarchar) as Year,
       3:    'H' + cast(dd.CalendarSemester as nvarchar) + ' CY ' + cast(dd.CalendarYear as nvarchar) as Semester,
       4:    'Q' + cast(dd.CalendarQuarter as nvarchar) + ' CY ' + cast(dd.CalendarYear as nvarchar) as Quarter,
       5:    cast(sum(SalesAmount)as money )as InternetSalesAmount
       6:  from
       7:     dbo.FactInternetSales fi 
       8:     inner join DimDate dd on fi.OrderDateKey = dd.DateKey
       9:  group by
      10:    dd.CalendarYear,
      11:    'CY ' + cast(dd.CalendarYear as nvarchar),
      12:    'H' + cast(dd.CalendarSemester as nvarchar) + ' CY ' + cast(dd.CalendarYear as nvarchar),
      13:    'Q' + cast(dd.CalendarQuarter as nvarchar) + ' CY ' + cast(dd.CalendarYear as nvarchar) 
      14:  order by
      15:    dd.CalendarYear, 3

    看NUNIT GUI测试的结果,我们可以看出有一个比较数据测试发现不同数据:

    NUNITTEST1
    实际上这个TOOLS是利用NUNIT的单元测试来测试或比较数据,并且这些UnitTest动态配制的,可以在SourceCode中看到:

       1:     [Test, TestCaseSource(typeof(ConfigurationManager), "GetTestCases")]
       2:      public void ExecuteQuery(QueryTestConfiguration queryTestConfiguration)
       3:      {
       4:        // get the connection of the QueryTest and check existance
       5:        ConfigurationManager configurationManager = ConfigurationManager.Instance();
       6:        ConnectionConfiguration connectionConfiguration = configurationManager.Connections[queryTestConfiguration.ConnectionRef];
       7:        Assert.IsNotNull(connectionConfiguration, String.Format("QueryTest {1}: ConnectionRef {0} does not exist", queryTestConfiguration.ConnectionRef, queryTestConfiguration.Name));
       8:   
       9:        // Open the connection
      10:        OleDbConnection connection = new OleDbConnection(connectionConfiguration.ConnectionString);
      11:        connection.Open();      
      12:   
      13:        // get the querytext and execute the query and store the rslt in dataTable
      14:        DataTable dataTable = new DataTable();
      15:        String queryText = String.Empty;
      16:        try
      17:        {
      18:          queryText = queryTestConfiguration.Query.GetQueryText(queryTestConfiguration.BaseDir);
      19:          OleDbDataAdapter adapter = new OleDbDataAdapter(queryText, connection);
      20:          adapter.SelectCommand.CommandTimeout = 0;
      21:          
      22:          dataTable.TableName = "rslt";
      23:          adapter.FillSchema(dataTable, SchemaType.Mapped);
      24:          adapter.Fill(dataTable);
      25:   
      26:          CorrectDataTable(dataTable);
      27:        }
      28:        catch (Exception ex)
      29:        {
      30:          System.Console.Out.WriteLine("Query:");
      31:          System.Console.Out.WriteLine(queryText);
      32:          System.Console.Out.WriteLine("Message:");
      33:          System.Console.Out.WriteLine(ex.Message);
      34:          Assert.Fail("Exception ouccured while executing the query: " + ex.Message);
      35:        }
      36:        finally
      37:        {
      38:          connection.Close();
      39:        }
      40:   
      41:        // save the DataTable to File
      42:        if (queryTestConfiguration.RsltFile != null)
      43:        {
      44:          FileInfo fi = new FileInfo(queryTestConfiguration.BaseDir + "\\" + queryTestConfiguration.RsltFile);
      45:          dataTable.WriteXml(fi.FullName,XmlWriteMode.WriteSchema);
      46:        }
      47:   
      48:        // Check Results
      49:        foreach (AssertConfiguration assert in queryTestConfiguration.Asserts)
      50:        {
      51:          assert.AssertThat(dataTable,queryTestConfiguration.BaseDir);
      52:        }
      53:      }

    使用了Nunit TestCaseSource attribute,然后其它那些配制的XML,全部通过XML序列化进行读取,具体参看SourceCode.

    另一种运行方法是使用MsBuild来实现。我们可以写一个bat文件,这样可以使用自动化命令行执行。事先要下载并Install MSBuild.Community Task。

    我们可以看到BIN目录有一个BI.Quality.proj文件,这个是MsBuild使用的。我们需要做一些配制,例如send mail,nunit lib src….具体查阅MSDN MSBuild.

    过程是通过MSBuild去执行Nunit,然后生成XML测试结果,通过NUnitReport.xsl转化成html,然后再send mail。

    Cmd:

    CMDREULST

    Report:

    BITESTRESULTPIC

    一切就是那么简单,可以看到MSBUILD的强大。这个使用是SQL SERVER2008 DEMO database  and dw。

    有时间会具体写一些关于细节问题,希望对您有帮助。

    Author: Petter liu  http://wintersun.cnblogs.com

  • 相关阅读:
    JDK+Jmeter 环境搭建
    APP自动化中三大定位工具
    APP自动化环境配置
    pytest生成allure报告
    pytest怎么标记用例?
    pytest中怎么实现参数化?
    pytest中怎么引用前置中的变量
    pytest_前置后置
    toast文本提示信息元素获取
    js处理日历
  • 原文地址:https://www.cnblogs.com/wintersun/p/1689082.html
Copyright © 2011-2022 走看看