简体   繁体   中英

What C# data store should I use?

I am trying to create a test framework and not sure what is best to use to store test case names and data that will be provided in XML file. For example, I want to test printer functionality so it has constructor, open printer connection, send data to printer, close printer connection. So the XML would be:

<Printer>
  <TestCaseName>"Printer_Construct"</TestCaseName>
    <Data1>"Printer1"</Data1>

  <TestCaseName>"Printer_OpenConnection"</TestCaseName>
    <Data1>"Printer1"</Data1>

  <TestCaseName>"Printer_PrintString"</TestCaseName>
    <Data1>"Printer1"</Data1>
    <Data2>"Printing my string"</Data2>

  <TestCaseName>"Printer_CloseConnection"</TestCaseName>
    <Data1>"Printer1"</Data1>
</Printer>

Here is how my test framework wanted to work:

1- when test operator runs the test framework, first it will load all the case names only into listbox1. It will not load test case data yet.

2- when test operator selects specific test case to run, it will load that test case into listbox2. So when it loads test case into listbox2, it will display test case name and test data(data1 and data2 as shown in xml struct above).

3- So now that test case in listbox2 is ready to be tested whenever test operator clicks the Run button.

So how can I store test case data? Should I store these data in memory? If so, what storing data feature should I use? If not storing these data in memory, does that means I will have to read the XML every time when accessing to test case data so is it good practice to do that?

thanks.

If you define the test cases in XML, then you might benefit from defining its structure in an XML Schema Definition file and using a tool to generate in-memory data structures as well as the deserializer (automated reader) from that .xsd file. The tool will provide you with a C# file that you can include in your program. You will be surprised how easy to work with this representation can be.

However, before you start, while your XML structure may work in this very simple initial case, it does not seem very maintainable. If the "data" nodes logically belong to the "test case" node that precedes them, it should be so even in the XML structure, like this:

<Printer>
    <TestCaseName Name="Printer_Construct">
        <Data1>"Printer1"</Data1>
    </TestCaseName>

    <TestCaseName Name="Printer_PrintString">
        <Data1>"Printer1"</Data1>
        <Data2>"Printing my string"</Data2>
    </TestCaseName>
</Printer>

Where you store this sort of information is largely dependant on what your interface is.

For a windows application (console or winforms), you can just store it in memory the first time it is needed and continue to look it up.

If, on the other hand, it is a web interface, I would highly recommend the built in .net web caching. It is extremely efficient and has powerful options for cache expiry like being able to have the file reload any time you change the file, and persist otherwise.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM