在Flex中设置功能测试
-
01-10-2019 - |
题
我正在为加载外部配置文件的应用程序设置功能测试套件。目前,我正在使用Flexunit的AddAsync函数加载它,然后再次测试内容是否指向存在并可以访问的服务。
问题的问题是,拥有这种两种(或多个)阶段方法意味着我在一个带有数十个断言的测试的背景下运行了所有测试,这似乎是一种使用框架的退化方法,使错误更难找到。有没有办法拥有异步设置之类的东西?还有另一个更好地处理此操作的测试框架吗?
解决方案
假设您使用Flexunit 4,可以从[BeforeClass]方法中调用AddAsync:
public class TestFixture
{
[BeforeClass]
public static function fixtureSetup() : void
{
// This static method will be called once for all the tests
// You can also use addAsync in here if your setup is asynchronous
// Any shared state should be stored in static members
}
[Test]
public function particular_value_is_configured() : void
{
// Shared state can be accessed from any test
Assert.assertEquals(staticMember.particularValue, "value");
}
}
话虽如此,测试访问文件的代码确实是集成测试。我也几乎无法争论使用Asmock :)
其他提示
这很容易,但是我花了2天的时间来弄清楚。解决方案:
首先,您需要在某个地方创建静态var。
public static var stage:Stage
有一个flexunitapplication.与Flexunit Framework创建的,在OnCreationComplete()函数上,您可以将阶段设置为先前创建的静态参考:
private function onCreationComplete():void
{
var testRunner:FlexUnitTestRunnerUIAS=new FlexUnitTestRunnerUIAS();
testRunner.portNumber=8765;
this.addChild(testRunner);
testStageRef.stage=stage //***this is what I've added
testRunner.runWithFlexUnit4Runner(currentRunTestSuite(), "testsuitename");
}
当您访问程序中的舞台时,应该替换为:
if(stage==null) stage=testStageRef.stage
不隶属于 StackOverflow