How can I effectively test a scripting engine?
Posted
by ChaosPandion
on Stack Overflow
See other posts from Stack Overflow
or by ChaosPandion
Published on 2010-06-03T00:20:01Z
Indexed on
2010/06/03
0:24 UTC
Read the original article
Hit count: 598
I have been working on an ECMAScript implementation and I am currently working on polishing up the project. As a part of this, I have been writing tests like the following:
[TestMethod]
public void ArrayReduceTest()
{
var engine = new Engine();
var request = new ExecScriptRequest(@"
var a = [1, 2, 3, 4, 5];
a.reduce(function(p, c, i, o) {
return p + c;
});
");
var response = (ExecScriptResponse)engine.PostWithReply(request);
Assert.AreEqual((double)response.Data, 15D);
}
The problem is that there are so many points of failure in this test and similar tests that it almost doesn't seem worth it. It almost seems like my effort would be better spent reducing coupling between modules. To write a true unit test I would have to assume something like this:
[TestMethod]
public void CommentTest()
{
const string toParse = "/*First Line\r\nSecond Line*/";
var analyzer = new LexicalAnalyzer(toParse);
{
Assert.IsInstanceOfType(analyzer.Next(), typeof(MultiLineComment));
Assert.AreEqual(analyzer.Current.Value, "First Line\r\nSecond Line");
}
}
Doing this would require me to write thousands of tests which once again does not seem worth it.
© Stack Overflow or respective owner