0

I'm working on a customization game in actionscript. There are several modules of the application. The application is data intensive. In order to boot the application you need to load a lot of other swf's , JSONs etc. I do not want to test the UI bits (for now) . What I want to test is :

  • No module crashes
  • I get sane answers

I am not concerned with the UI and visual anomalies.

I want to write separate Test Suites for the modules and separate test classes. To be more organized.

Question:

In order to test even the simplest functions I need the X,Y,Z data to be loaded. X,Y,Z data is common for all modules.

How do I write different test classes and suites and preload the data only once and use that copy of data through out the tests. Most data is not changed through the course of tests.

abatishchev
  • 98,240
  • 88
  • 296
  • 433
Fahim Akhter
  • 1,617
  • 5
  • 31
  • 49
  • 2
    You should consider rethinking your strategy, unless it is really the data you want to test, and not the game logic. You don't say anything about the context, so I assume there are multiple modules with game logic. To test each individually, it is usually best to mock *all* dependencies and test only one module's logic at a time. A limited data set in a test double, containing a valid result, and one each for all edge cases and failures should be enough. You won't need loading etc. - these are different functionalities, which should be tested in a separate test! – weltraumpirat May 23 '12 at 14:46
  • The data required for the tests is a very large set. I don't want to make mock data. Instead use the real data and load it from the servers. The question is once the data is loaded how do I reuse it in different test classes, instead of having to initialize it in every test class. – Fahim Akhter May 24 '12 at 06:02
  • No, the question is: Why do you want to use live data for your tests? You said that your tests should prove that your modules are correct - and for that you should use mock data. If, on the other hand, you want to prove that your *data* is correct, you should set up a test program that loads all the data and then runs a set of calculations - in *addition* to unit tests, because you still need to know that your program is correct. The idea of automated testing is to test each part in your application separately, so that when a test fails, you know exactly where the problem is. – weltraumpirat May 24 '12 at 06:10
  • You can think of my live data as my mock data because it's static. The only thing is I don't want to waste all that time reprogramming it. I have all this data on my server which is static and I load it procedurally. I just don't want to load that data over and over again. – Fahim Akhter May 24 '12 at 06:44

1 Answers1

0

I usually create one or more test versions of each data object Class I need that is a SubClass of the data object with all the properties filled out.

So in the [Before] method, I might set these up like this:

testVO = new TestMyVO();

and in the test cases:

myObjectThatNeedsAVO.myVO = testVO;

So all test cases that need a MyVO, I can then reuse that TestMyVO. If I need multiples, I might create a factory that can create one of several, and then call the one I particularly need to exercise whatever I'm exercising.

Amy Blankenship
  • 6,485
  • 2
  • 22
  • 45
  • Now, imagine testvo is a sync with a 5 minute loading window. I would not want to do testVO = new TestMyVO() in every before of every test class. But just once, and use that in all test classes. How do I manage that? – Fahim Akhter May 24 '12 at 05:58
  • 1
    You don't. That's the point. Consider, for a second, that there is an error in your data set... Now **all** your tests will fail, even though the program works correctly. The same would happen if the network went down. You would have no clue about the cause of the problem. This kind of test setup will not help you - you might as well run the application itself and use a debugger. – weltraumpirat May 24 '12 at 06:14
  • I completely agree with you on that part. But here is the thing my data are things I have already known to be true, it doesn't change (not for the things I need to test) consider I have 1,3,5 and I am testing an Addition function 1,3,5 is going to be constant always. What I need is to make sure that in the new build I didn't mess up Addition function and it always returns 1+3 = 5 . I know the input and the output, just need to make sure the function is correct. – Fahim Akhter May 24 '12 at 06:42
  • Well, apart from the fact that 1+3=4 (duh), you could download all your data and store it in a test double class. That way, you will test against the data you know to be true, and still not use the network and a database in your tests. – weltraumpirat May 24 '12 at 08:13
  • You're missing the point. You should not be testing with real data loaded from the server. Your TestVo is one that's loaded with known values. weltraumpirat: I'd record data over the wire for mocks (to test the whole system in action, or to work on visual logic without hitting the server), but I think that's an extra layer of "stuff" on top of the layer you're testing. If you can actually do this, it probably means your service layer has too many responsibilities. – Amy Blankenship May 24 '12 at 16:21
  • http://forums.adobe.com/message/2346676#2346676 The situation defined there is exactly my situation (read the fourth reply telling the details). I think I'm just rubbish at explaining myself maybe this will help :) – Fahim Akhter May 25 '12 at 07:25
  • If the problem is actually race conditions putting things into a bad state (as in the thread you pointed at), then the solution is really to inject your components with the data in all sorts of different orders and make sure it can't bork anything. – Amy Blankenship May 26 '12 at 18:08