create new tag
, view all tags

TWiki formatting - Doing a test report

2013-08-07 - 21:05:36 by StefanAlthoefer in Applications

Recently I started creating test reports in our company's Twiki, which is already used for project management and knowledge base.

Below you find some formatting tricks that I use for consistent rendering and topic automation.


For compact presentation of test conditions I wanted a two column table, like in the image shown. But alas, in the right column I need structured text which is not possible with Twiki's lightwight table implementation.

I considered some solution:

  • Stop HTML hacks wich are seen all around the twiki.org website. This is hard to maintain and if more than one person is doing it a consistent style is not likely to be seen.
  • Stop Installing the MediaWikiTablePlugin. The syntax is weired, although I didn't test it. More worse: My team (including me) is not familiar with the syntax.
  • Yes / Done I came up with some parameterized variables (macros) which hide the nasty HTML details. I was inspired to this solution after having seen some obscure wikimedia templates.

Table Macros

The macros are like this:

   * Set DTABLE = <div style="%DTABLE_STYLE%"><table cellpadding="6" border="1" rules="all" class="twikiTable">
   * Set DTABLEROW = <tr valign="top" ><td> %DEFAULT% </td><td>
   * Set DTABLEEND = </td></tr></table><div>

Read the "D" as in data-table, or choose a better name for yourself. The macros are stored in TWikiPreferences, so they can be used in any test report.

Consider this example:

IEC 60068-2
   * 70 C
   * 24 h
   * 1 h temperature rise/fall
%DTABLEROW{"*Device* %BR% *under Test*"}%
Janz Tec emPC-A500
   * SY-IPC-82000
   * Freescale i.mx51 (600MHz)
   * 256 MByte RAM
   * Linux 2.6.35
   * Perl Testsuite running
      * memory test
      * netio (eth0, eth1)
      * CAN selftest (testself2)
      * serial port loopbacktest (sertest -c 3)

I think this is quite readable. It renders as:

Standards IEC 60068-2
  • 70 C
  • 24 h
  • 1 h temperature rise/fall
under Test
Janz Tec emPC-A500
  • SY-IPC-82000
  • Freescale i.mx51 (600MHz)
  • 256 MByte RAM
  • Linux 2.6.35
  • Perl Testsuite running
    • memory test
    • netio (eth0, eth1)
    • CAN selftest (testself2)
    • serial port loopbacktest (sertest -c 3)

Table Macro Explanation

This macro is used to spit out the start of the table. It has an optional parameter DTABLE_STYLE which can be used to control the positioning of the table. You can use CSS style parameters here.

  • %DTABLE{DTABLE_STYLE="margin-left:100px;"}%
    • This indents the table by 100 px.
  • %DTABLE{DTABLE_STYLE="float:right;"}%
    • This lets the table float to the right.

This macro starts a new (or the first) row. It takes the content for the first column as it's default parameter. Hence it is referred as %DEFAULT% inside the macro. It is passed to the macro without a parameter name (refer to the example above).

This macro ends the table by closing all open HTML tags.

More Table Ideas

The above macros utilize the twiki CSS table styles. You might not like them as

  • the grid is missing vertical lines (although some browsers show them)
  • the grid is very light, which makes the lines disappear on some TFT screens due to color inversion

You could add your own styles inside the twiki CSS files and refer to them. If you cannot change the CSS files, you can also hack the styles into the macros as shown below (names changed so both versions can be tested in paralell). Note that boarder-color is not inherited from <table> to <td>, so it must be specified for each cell.

   * Set XTABLE = <div style="%XTABLE_STYLE%"><table cellpadding="6" border="1" rules="all" style="border-color: #c0c0c0; border-width: 1px; border-style: solid; border-collapse: collapse;">
   * Set XTABLEROW = <tr valign="top"  ><td style="border-color: #c0c0c0; border-width: 1px; border-style: solid;"> %DEFAULT% </td><td style="border-color: #c0c0c0; border-width: 1px; border-style: solid;">
   * Set XTABLEEND = </td></tr></table></div>

And horror, you can even nest tables (goto raw-view for the code):

musicians mike and his band
  • mike
  • paul
  • mary
  • Track 1
  • Track 2
  • Track 3
  • Track 4
    Time Remark
    4:37 Scratch on the media

Generate Summary of Test results

Throughout my test report TWiki topic each performed test has its heading with a subsequent subheading Test result. This is written as follows.

---++ High Temperature Operation Test


---++++!! Test result

| High temperature operation test (70 C) | %ICON{"choice-yes"}% | _optional comment_ |

The table renders as.

High temperature operation test (70 C) Yes / Done optional comment

Well, it would be nice to have a summary of all the test results at the beginning of the report. However this is more than a simple %TOC% can do.

How to do it?

I use one of my favorite plugins for this purpose: FilterPlugin. This plugin searches for any text (a Twiki syntax tables in my case) and inserts them into the topic where you need it:

%EXTRACT{topic="%TOPIC%" expand="off" pattern="^---\+\+\+\+!* +Test result[\r\n]*(\|.*?\|)$" format="$1$n"
header="| *Test* | *Result* | *Comments* |$n"

This renders to something like this (simulated):

Test Result Comments
High temperature operation test (70 C) Yes / Done optional comment
Low temperature operation test (-10 C) Yes / Done  
Humidity Cyclic operation test (40 C, 97 %) No HV unit sparked

Filter Plugin Explanation

The plugin searches the raw topic text due to the setting expand="off". It searches it's own topic due to topic="%TOPIC%".

pattern controls what is matched:

  • ^---\+\+\+\+!* + - Matches for the heading syntax ---++++ at the start of a line (due to ^). This may optionally followed by ! if you prefer to hide this heading from the table of contents. Finally + (space followed by plus) allows one or more spaces.
  • Test result[\r\n]* - This part of the pattern matches for the heading text (exact match) followed by the line break. [\r\n]* allows any sequence of CR or NL characters, so we even handle one or more empty lines or CRNL sequences.
  • (\|.*?\|)$ - This finally matches the TWiki table, which is a line that starts and ends with |. Between those, it matches for any character but uses the special non-greedy *? quantifier to match only as little content as necessary. Using the greedy quantifier (*) here would match as much as possible. This could start one one line and match up to the end of a TWiki table many lines later. Anything between the brackets (the table line) is remembered for later use.

format is utilized to produce output each time the pattern matches. In this case it is easy: $1 just outputs the content remembered by the brackets in the pattern. $n generates a newline (just as %SEARCH% does).

Finally header is the header string prepended to output.


Thank you Stefan for sharing this with the TWiki community!

-- Peter Thoeny - 2013-08-07


Topic attachments
I Attachment History Action Size Date Who Comment
PNGpng report-100.png r1 manage 5.0 K 2013-08-07 - 20:49 StefanAlthoefer  
PNGpng report.png r1 manage 22.4 K 2013-08-07 - 20:35 StefanAlthoefer Test report sample
Edit | Attach | Watch | Print version | History: r2 < r1 | Backlinks | Raw View | Raw edit | More topic actions
Topic revision: r2 - 2013-08-07 - StefanAlthoefer

Twitter Delicious Facebook Digg Google Bookmarks E-mail LinkedIn Reddit StumbleUpon    
  • Help
  • Learn about TWiki  
  • Download TWiki
This site is powered by the TWiki collaboration platform Powered by Perl Hosted by OICcam.com Ideas, requests, problems regarding TWiki? Send feedback. Ask community in the support forum.
Copyright © 1999-2017 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.