This project is read-only.

Setup and Cleanup

With the mean of the two elements setup and cleanup, you're able to define commands that will be executed before or after the test execution. This could be really useful to load some data in tables or clean these tables before you effectively run your test.

The xml element setup must be located before the xml element system-under-test. In the same way, the xml element cleanup must be located after the xml element assert.

<test>
  <setup>
    ...
  </setup>
  <system-under-test>
    ...
  </system-under-test>
  <assert>
    ...
  </assert>
  <cleanup>
    ...
  </cleanup>
</test>

Tasks (parallelism vs sequential)

Some commands could be executed in parallel. It's usually the case when you're loading independent tables or starting independent services. At the opposite, some commands should be executed sequentially: clean a table by removing all rows then after load the table with new data.

Parallelism is usually a good way to improve performance when loading or truncating tables.

To group a set of commands, you must surround them by the xml element tasks. If you want to use them sequentially you must specify the xml attribute parallel with the value false. If this attribute is not specified the default behavior is the parallelism.

In the sample bellow the two tables will be loaded in parallel.
  <tasks parallel="true">
    <table-reset  name="Users"/>
    <table-reset  name="KeyDates"/>
  </tasks>

In the sample bellow the two tables will be loaded sequentially.
  <tasks parallel="false">
    <table-reset  name="Users"/>
    <table-reset  name="KeyDates"/>
  </tasks>

Inheritance

It could be really boring to write (or copy/paste) the same setup commands for each test. To avoid this, NBi has a feature named Inheritance of setup/cleanup. If some tests share the same setup/cleanup commands, you can move the commands at the group level. The commands will be executed for each test.

In the sample bellow, the two tests will be preceded by a reset (truncate) of the tables Users and KeyDates.
<group name="Share some steps">
  <setup>
    <tasks>
      <table-reset  name="Users"/>
      <table-reset  name="KeyDates"/>
    </tasks>
  </setup>
  <test name="first test">
    ...
  </test>
  <test name="second test">
    ...
  </test>
</group>

You can create several layers of inheritance by defining groups in groups.

You can add additional commands for each test. For this you must specify a new setup (or cleanup) element inside the test. This setup command, at the test level, will be executed after the setup commands defined at the level just before.

In this sample the first test will be preceded by the truncation of tables Users, KeyDates and FirstTable. The second test will be preceded by the truncation of tables Users, KeyDates and SecondTable.
<group name="Share some steps">
  <setup>
    <tasks>
      <table-reset  name="Users"/>
      <table-reset  name="KeyDates"/>
    </tasks>
  </setup>
  <test name="first test">
    <setup>
      <table-reset  name="FirstTable"/>
    </setup>
    ...
  </test>
  <test name="second test">
    <setup>
      <table-reset  name="SecondTable"/>
    </setup>
    ...
  </test>
</group>

Run Once

A set of tests using the same configuration of the database and without insert/update/delete commands will be able to take advantage of feature run-once. It's not needed to execute the command loading the database or to start the service for each test, once will be enough.

If the tests are grouped within a group element, you can already use the inheritance of setups described above to write once your setup's commands. To specify that you want to apply some of them only once, you need to specify at the task level the attribute run-once with the value true.

In the sample bellow, the first set of tasks will be executed once (before the execution of the first test) and the second will be executed before each tests.
<setup>
  <tasks run-once="true">
    <table-reset  name="Users"/>
    <table-reset  name="KeyDates"/>
  </tasks>
  <tasks>
    <table-load   name="Users"
        file ="Users.csv"
     />
    <table-load   name="KeyDates"
        file ="KeyDates.csv"
     />
  </tasks>
</setup>

Note: for the moment the attribute run-once is not designed to work with cleanup decorations. If you use it, the cleanup function will be executed (once) after the first test (and not the last) ... probably not what you're looking for.

Available commands

The following list of activable by commands is available:

Failures

If one of the commands requested during the setup is failing then the test will be considered as failed and will report the exception raised during the setup. On the other hand if one of the commands executed during the cleanup has failed this will not influence the result of your test.

In both case, commands after the failed command will not be executed.

Last edited Oct 6, 2014 at 10:24 PM by Seddryck, version 6

Comments

No comments yet.