FlexUnit 4.1
FlashBuilder 4.5.1
BACKGROUND
I'm trying to test a custom Flex 4 skinnable component, using the FlexUnit UIImpersonator class. If I run my tests from a FlashBuilder Spark only project everything works fine. If I try to test from a project with the mx component set on the buildpath I get a "getElementIndex not available in non Flex 4 projects" error.
QUESTION
Can I unit test spark components in FlexUnits visual test environment while still having the mx component set on the classpath?
RESEARCH
UIImpersonator delegates it's method calls to a "testEnvironment". The implementation used for this "testEnvironment" is decided by the VisualTestEnvironmentBuilder class and the FlexEnvironmentBuilder class. If the FlexEnvironmentBuilder class can find the "mx.core.Container" on the classpath it returns a MX environment, else a Spark environment. Only the spark environment has valid implementations for Flex 4 relevant method calls on the UIImpersonator – like the addElement method.