Search code examples
unit-testingconditional-compilationappharbor

Can AppHarbor set a conditional compilation symbol during build?


Can AppHarbor set a conditional compilation symbol during build? Maybe simply: AppHarbor

I have some tests that can't run on the server (they rely on test data files).

If AppHarbor could set a conditional compilation symbol, then I could add an [Ignore] attribute on the test when that symbol is present.

Or, is there a better or different way to ignore specific tests when running at AppHarbor?

Or, is there a way for the test code to correctly reference a test data file residing in the project?

Thanks! Glen

Edit: I got my test to work by embedding the data file as a Resource in the test project. Not ideal, but okay for now. However, would still like to know if compilation symbols can be set as described.


Solution

  • Setting an "AppHarbor" compilation symbol is an interesting suggestion, but it's not currently supported on AppHarbor. You might want to add it as a feature request.

    When running your tests the Environment appSetting is set to test. You could use that conditionally to skip certain tests. If you prefer to have your own configuration you could use a Web.Test.Config file to apply any necessary transformations that'll allow you to determine whether tests should be run or not.

    Both approaches are described in this article.

    Generally my recommendation would be to avoid relying on files that are not present when running tests. That'll also make the application work in any CI environment. Including the file as an embedded resource as you describe is an option, but it should also be possible to include it in your project with the Build Action property set to Content and it'll be available in the output directory.