Have to admit I'm not too experienced with using FlexUnit for CS Extension projects, but I know it can be done.
If the problem is obvious to someone else maybe they can chime in. In the meantime can you give some more details:
- It sounds like your tests are actually running, but failing, is that right? What are the errors? Have you tried debugging while the tests are running?
- Which FlexUnit version are you using?
- How are you launching the tests?
My tests are not failing they are erroring. I have just tried debugging and I never get into the tests or the code that is being tested. I believe this is because the extension is waiting for Premiere (the extension host) to start and it never gets started.
I'm using Flexunit 4 and the Hamcrest extensions.
I'm running the tests from within the Flash Builder GUI using the run button in the Flex Unit Results page. This gives me a dialog to choose which tests to run and I have cut it down to a single test for now. Then I get the message about needing a debug Flash Player - click OK on that and all the tests error and the Launching FlexUnit Application dialog sits there waiting to connect to the running application. The only way out is to Cancel that now. So it appears the flexunit tests are not connecting to a running application but no hint as to what that app might be.
I think I understand why it needs the Flash Player - that's the window it reports the flexunit run in - black with white text saying 1 test, 1 error etc and telling me I can now close it. So the tests have finished.
I think I'm missing something obvious but not sure what.
I think I have worked out a way to do this after much trial and error.
1. Create a new Flex Project in the same workspace as the extension. Called something like ExtensionTests
2. In the test project properties set use the Build Path to include the source from the extension. Probably have to be careful not to change this code from inside the test project.
3. Add any service references to the test project. I have 2 web services I use and these have to be referenced in the test project else I get compilation errors. I also called them the same names and modified the constructors in the same way I did for the extension.
4. Create a test case as normal for a class in the source reference.
5. Run the tests. They all fail as expected.
6. Modify a single test to actually do something to cause it not to fail.
7. Re-run tests. Get the expected result of 1 success and N failures.
Whilst not ideal because I have a reference to the real source in my test project I can at least test this source now.
Hope this helps anyone else who reads this.