如何自动化SSAS的MDX测试 [英] How to automate MDX testing of SSAS
问题描述
我已经开发了一些MDX查询,用于测试我们的SSAS多维数据集.我想自动执行这些查询,这样我就可以通过单击一个按钮来执行所有查询,最好是根据其输出显示绿色/红色条.
I've developed some MDX queries which are used to test our SSAS cube. I would like to automate these queries so that I could execute them all with a click of a button and ideally green bar/red bar based on their output.
有没有一种方法可以将这些查询与Visual Studio挂钩以实现此行为?
Is there a way I could hook these queries up with Visual Studio to get this behavior?
推荐答案
您可以在此处尝试任何单元测试框架.尽管单元测试并非旨在用于此类用途,但在此处可能会很有用-测试运行器开箱即用的红色/绿色指示器.
You can try any unit testing framework here. Although unit tests aren't intended for such use, they can be useful there - test runners have red/green indicator out of the box.
使用ADOMD.NET( http://j.mp/NtKFih )执行mdx的写测试在执行过程中将失败测试.您还可以使用 CellSet 对象调查结果,并确定测试是否通过.
Write test which executes mdx using ADOMD.NET ( http://j.mp/NtKFih ) and exception during execution will fail test. You can also investigate result using CellSet object and decide if test has passed.
使用Microsoft的单元测试框架的简单示例(需要引用System.Data.dll和Microsoft.AnalysisServices.AdomdClient.dll):
Simple example using Microsoft's Unit Testing Framework (references To System.Data.dll and Microsoft.AnalysisServices.AdomdClient.dll are required):
using Microsoft.AnalysisServices.AdomdClient;
...
[TestMethod]
public void CubeHealthCheck1()
{
using (AdomdConnection conn = new AdomdConnection("Data Source=localhost;
Initial Catalog=SejmCube")) //your connection string here
{
conn.Open();
AdomdCommand cmd = conn.CreateCommand();
//your mdx here
cmd.CommandText = "SELECT NON EMPTY { [Measures].[Glosow Przeciwko] }
ON COLUMNS FROM [Sejm]";
CellSet cs = cmd.ExecuteCellSet();
}
}
任何异常都将失败测试(例如,无连接)-您可以添加try/catch并在消息中指出出了什么问题.
Any exception will fail test (no connection for example) - you can add try/catch and in message inform what went wrong.
您可以从例如测试列表编辑器"窗口运行此测试 然后在测试结果"窗口中,您得到带有指示符的结果 >
You can run this test from for example Test List Editor window and then in Test Results window you have result with indicator
如果您不想使用单元测试框架,则可以开发自定义Visual Studio扩展( http://j.mp /QfMNQt ),内部逻辑类似.
If you don't want using unit testing framework, you can develop custom visual studio extension (http://j.mp/QfMNQt) with similar logic inside.
这篇关于如何自动化SSAS的MDX测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!