I have a few unit tests that require very large strings for the test data. I do not want to declare the HTML string in the test itself as this can obscure that actual test. Rather, I would like to load these strings from an external resource for each test.
Though I am not running the same test with different sets of data, parameterized tests looks to be a viable solution; however, I am having difficulty getting the following example to work.
Note: This code is based on the TestNG example.
package flexUnitTests
{
import helpers.HTMLDataHelper;
import org.flexunit.runners.Parameterized;
import org.hamcrest.assertThat;
import org.hamcrest.text.containsString;
[RunWith("org.flexunit.runners.Parameterized")]
public class SimpleTestCase
{
private var parameterized:Parameterized;
public static var dataLoader:HTMLDataHelper = new HTMLDataHelper("data/layer.html");
[DataPoint(loader="dataLoader")]
public static var htmlContent:String;
[Test(dataprovider="htmlContent", description="Tests something.")]
public function mustPassThisSimpleTest(htmlContentParam:String):void
{
assertThat(htmlContentParam, containsString("head"));
}
}
}
When I run this test I receive the following error message:
Error: There was an error retrieving the parameters for the testcase: cause invalid value for parameterized field htmlContent: null
Any thoughts as to what might be the solution to this problem might be?
One solution I found was to run the tests in the class with the
Theories
runner as shown below.However the side effect is that all of your tests within the test class will display cryptic error messages when the tests fail. For example,
instead of the much more useful
Though this does "solve" the problem I was having, IMHO the trade off in message clarity is not worth being able to load data from external sources.