Customizes restfixture code for Fitnesse-20140630

Source: Internet
Author: User
Tags ranges uppercase letter

The fitnesse plug-in restfixture outputs the test result as HTML text in the latest fitnesse version, instead of HTML. This blog post records the restfixture code process.

Prepare the development environment

Assume that you have correctly installed JDK, Eclipse, ant, and maven. For the installation steps, see the blog:

Http://www.cnblogs.com/fitnessefan/p/3895706.html

Use git in eclipse to download the fitnessekit source code on git.oschina.net.

Https://git.oschina.net/fitneesefan/FitnesseKit.git

Steps:
Eclipse menu> WINDOW> open perspective> other... > Git> clone a git repository and add it to this view:

Clone fitnessekit to D: \ git \ fitnessekit

Compile and start fitneese

Compile fitneese

?
1 D:\git\FitnesseKit\fitnesse >ant

Compile restfixture

?
1 D:\git\FitnesseKit\RestFixture>mvn clean package

Start fitneese

?
1 D:\git\FitnesseKit\fitnesse >ant run

Open the fitnesse Website:

  • Enter http: // localhost: 8001 in the browser

Add test wiki page

On the fitnesse FrontPage, click the edit button:

Insert code:

?
12345 Check whether restfixture is correctly installed| RestFixtureInstallTest | Baidu Map Service API Test Set| BaiduMapApiSuite |

Click Save:

You can see:

  • Restfixtureinstalltest is a link http: // localhost: 8001/restfixtureinstalltest, because the page already exists
  • Baidumapapisuite has?Link: http: // localhost: 8001/baidumapapisuite? Edit & nonexistent = true

The Wiki Syntax of fitnesse is described as follows:

Two English words (such as helloworld) Starting with an uppercase letter are connected together. They are called wikiword and direct to the link http: // localhost: 8001/helloworld. If this Wiki page exists, point to it, otherwise it is displayed as "? ", And points to the link to create and modify the wiki page.

Click the restfixtureinstalltest link and you will see:

After editing, the Wiki text is:

?
12345678910 !define TEST_SYSTEM {slim} !path D:\git\FitnesseKit\RestFixture\target\dependencies\*!path D:\git\FitnesseKit\RestFixture\target\smartrics-RestFixture-3.1-SNAPSHOT.jar!path D:\git\FitnesseKit\RestFixture\extra\slf4j-simple-1.6.6.jar| Table:smartrics.rest.fitnesse.fixture.RestFixture | http://www.w3school.com.cn || GET | /example/xmle/note.xml | 200 | Content-Type: text/xml | //body[text()="Don‘t forget the meeting!"]|

Click Cancel to return to the wiki page,

Test wiki page

Click test to run the test:

Output the test result as HTML text, not html

Modify the restfixture code until the test result is displayed as a normal HTML analysis test result.

Test result table:

Table: smartrics. Rest. fitnesse. fixture. restfixture Http://www.w3school.com.cn
Get /Example/xmle/Note. xml 200 Content-Type: & nbsp; text/XML <br/> <I> <SPAN class = 'fit _ label'> expected </span> </I> <HR/> <br/> Content-Length & nbsp;: & nbsp; 209 <br/> Content-Type & nbsp;: & nbsp; text/XML <br/> last-modified & nbsp;: & nbsp; Mon, & nbsp; 29 & nbsp; Jul & nbsp; 2013 & nbsp; 17:25:37 & nbsp; GMT <br/> Accept-ranges & nbsp;: & nbsp; bytes <br/> etag & nbsp;: & nbsp; "344628a4808cce1: 28cc" <br/> Server & nbsp;: & nbsp; microsoft-IIS/6.0 <br/> X-powered-by & nbsp;: & nbsp; ASP. net <br/> Date & nbsp;: & nbsp; Sun, & nbsp; 03 & nbsp; Aug & nbsp; 2014 & nbsp; 01:20:44 & nbsp; GMT <br/> <I> <SPAN class = 'fit _ label'> actual </span> </I> // Body [text () = "Don't & nbsp; forget & nbsp; The & nbsp; meeting! "] <Br/> <I> <SPAN class = 'fit _ label'> expected </span> </I> <HR/> <br/> & lt ;? Xml & nbsp; version = "1.0" & nbsp; encoding = "ISO-8859-1 "? & Gt; <br/> & lt ;! -- & Nbsp; copyright & nbsp; w3school.com.cn & nbsp; -- & gt; <br/> & lt; Note & gt; <br/> & nbsp; & nbsp; & lt; To & gt; George & lt;/to & gt; <br/> & nbsp; & lt; from & gt; John & lt;/from & gt; <br/> & nbsp; & lt; heading & gt; reminder & lt;/heading & gt; <br/> & nbsp; & lt; Body & gt; don't & nbsp; forget & nbsp; The & nbsp; meeting! & Lt;/Body & gt; <br/> & lt;/Note & gt; & nbsp; <br/> <I> <SPAN class = 'fit _ label'> actual </span> </I>

The markdown syntax does not support tables. You can only paste HTML text from fitnesse directly here.

Analyze the above table and find that the test result replaces the original wiki content:

  • The first column (Table: smartrics. Rest. fitnesse. fixture. restfixture) in the first row is set with the green background color.
  • The second column (/example/xmle/Note. XML) in the second row is replaced with the <A> tag, which correctly displays HTML.
  • The fourth column of the second row (Content-Type :...) It is replaced by HTML text and cannot be correctly displayed in HTML.

*It seems that I have found a clue to the problem. I will compare the reason why the second column is correct and the fourth column in the second row is incorrect.

Next, you can find HTML fields in all files:

Eclipse menu> Search... > File search

Next, go through a painful and helpless human flesh search and find the key code:

File: D: \ git \ fitnessekit \ fitnesse \ SRC \ fitnesse \ testsystems \ slim \ htmltable. Java

?
1234 static boolean qualifiesAsHtml(String text) {    // performance improvement: First check 1st character.    return text.startsWith("<") && HTML_PATTERN.matcher(text).matches();  }

Function NameQualifiesashtmlIt meansCan be used as HTML 
The Function Code indicates that the regular HTML expression must start with "<" and comply with the html_pattern definition.

Press F3 on html_pattern, or right-click open declaration from the menu to see the definition of html_pattern:

?
1234 private final static Pattern HTML_PATTERN = Pattern.compile("^<(p|hr|pre|ul|ol|dl|div|h[1-6]|hgroup|address|" +          "blockquote|ins|del|object|map||video|audio|figure|table|fieldset|canvas|a|em|strong|small|mark|" +          "abbr|dfn|i|b|s|u|code|var|samp|kbd|sup|sub|q|cite|span|br|ins|del|img|embed|object|video|audio|label|" +          "output|datalist|progress|command|canvas|time|meter)([ >].*</\\1>|[^>]*/>)$", Pattern.CASE_INSENSITIVE | Pattern.DOTALL);

Check the test result table again:

  • The HTML text of the second column (/example/xmle/Note. XML) in the second row is:

    <A href = "http://www.w3school.com.cn/example/xmle/note.xml">/example/xmle/Note. xml </a>

  • The fourth column of the second row (Content-Type :...) The HTML text of is:

    Content-Type: & nbsp; text/XML <br/> <I> <SPAN class = 'fit _ label'> expected </span> </I> <HR/> <br/> Content-Length & nbsp;: & nbsp; 209 <br/> Content-Type & nbsp;: & nbsp; text/XML <br/> last-modified & nbsp;: & nbsp; Mon, & nbsp; 29 & nbsp; Jul & nbsp; 2013 & nbsp; 17:25:37 & nbsp; GMT <br/> Accept-ranges & nbsp;: & nbsp; bytes <br/> etag & nbsp;: & nbsp; "344628a4808cce1: 28cc" <br/> Server & nbsp;: & nbsp; microsoft-IIS/6.0 <br/> X-powered-by & nbsp;: & nbsp; ASP. net <br/> Date & nbsp;: & nbsp; Sun, & nbsp; 03 & nbsp; Aug & nbsp; 2014 & nbsp; 01:20:44 & nbsp; GMT <br/> <I> <SPAN class = 'fit _ label'> actual </span> </I>

Apparently, the fourth column in the second row (Content-Type :...) Cannot be recognized as HTML.

Next, there are two ways to go:

  1. Modify the qualifiesashtml function in fitnesse and return true directly.
  2. Modify the test result in restfixture and set a <span> tag.

I have tried 1st steps. The compilation is successful, but countless test results fail during the automatic unit test and acceptance test after compilation.
The main reason is that "<" and ">" are of critical use. See the fitnesse acceptance case below:

Http://fitnesse.org/FitNesse.SuiteAcceptanceTests.SuiteSlimTests.TestComparators

The results show that the 1st paths are different. For a fixture, you obviously have to change the fitneese syntax.

The next step is to modify the test results in restfixture and set a <span> tag

Modify the restfixture code

Restfixture is implemented as a slim tabletable. Here is the help documentation for slimtable:

Next, search for "Pass:" In project restfixture, which is easy to locate:

D: \ git \ fitnessekit \ restfixture \ SRC \ main \ Java \ smartrics \ rest \ fitnesse \ fixture \ slimformatter. Java

?
1 102expected.body("pass:" + Tools.makeContentForRightCell(expected.body(), typeAdapter, this, minLenForToggle));

Add a <span> tag to the test result and modify the row:

?
1 102expected.body("pass:<span>" + Tools.makeContentForRightCell(expected.body(), typeAdapter, this, minLenForToggle) + "</span>");

Compile restfixture:

?
12345678910 D:\git\FitnesseKit\RestFixture>mvn compile      ...[INFO] Compiling 1 source file to D:\git\FitnesseKit\RestFixture\target\classes[INFO] ------------------------------------------------------------------------[INFO] BUILD SUCCESS[INFO] ------------------------------------------------------------------------[INFO] Total time: 25.678 s[INFO] Finished at: 2014-08-03T13:13:07+08:00[INFO] Final Memory: 18M/64M[INFO] ------------------------------------------------------------------------

Compile and generate a new class file: slimformatter. Class

The MVN compile Command did not generate a new smartrics-RestFixture-3.1-SNAPSHOT.jar

Therefore, you need to modify http: // localhost: 8001/restfixtureinstalltest

?
123 !path D:\git\FitnesseKit\RestFixture\target\smartrics-RestFixture-3.1-SNAPSHOT.jar-->!path D:\git\FitnesseKit\RestFixture\target\classes

Run the test case http: // localhost: 8001/restfixtureinstalltest again:

Yeah! Perfect.

Is it over now? Apparently not, the next step is to execute the MVN package, package to generate the smartrics-RestFixture-3.1-SNAPSHOT.jar.

Modify unit test code and package restfixture

Run the MVN package command to package:

?
12345678910111213141516 D:\git\FitnesseKit\RestFixture>mvn packageResults :...Failed tests:   shouldDisplayPassOnCheckIfExpectedAndActualMatch_whenDisplayingActual(smartrics.rest.fitnesse.fixture.SlimFormatterTest): (..)  shouldDisplayPassOnCheckIfExpectedAndActualMatch(smartrics.rest.fitnesse.fixture.SlimFormatterTest): (..)  shouldDisplayXmlDataInActual(smartrics.rest.fitnesse.fixture.SlimFormatterTest): (..)    ...Tests run: 264, Failures: 3, Errors: 6, Skipped: 0[INFO] ------------------------------------------------------------------------[INFO] BUILD FAILURE[INFO] ------------------------------------------------------------------------[INFO] Total time: 14.866 s[INFO] Finished at: 2014-08-03T19:32:44+08:00[INFO] Final Memory: 18M/133M[INFO] ------------------------------------------------------------------------...

During packaging, three tests failed during unit testing.
Shoulddisplaypassoncheckifexpectedandactualmatch_whendisplayingactual function in row 70th of the file D: \ git \ fitnessekit \ restfixture \ SRC \ test \ Java \ smartrics \ rest \ fitnesse fix\ Ture:

?
1234567 public void shouldDisplayPassOnCheckIfExpectedAndActualMatch_whenDisplayingActual() {    SlimCell c = new SlimCell("something matching logically abc123");    ...    assertThat(            c.body(),            is(equalTo("pass:something&nbsp;matching&nbsp;logically&nbsp;abc123<br/><i><span class=‘fit_label‘>expected</span></i>)));}

According to the previous code modification, pass: XXX should be changed to pass: <span> XXX </span>
Modify the assertthat statement:

?
123 assertThat(            c.body(),            is(equalTo("pass:<span>something&nbsp;matching&nbsp;logically&nbsp;abc123<br/><i><span class=‘fit_label‘>expected</span></i>)));

Execute the MVN package again. The number of failed test cases is 2, which indicates that the modification is correct.

Modify the other two failed test cases,

  • Run the MVN package and report 0 failures, 6 errors, and build failure.
  • Run MVN clean package, 0 failed, 0 failed, build success, the smartrics-RestFixture-3.1-SNAPSHOT.jar generated the new version.

For specific modification content, go to git to view the corresponding commit:

  • Http://git.oschina.net/fitneesefan/FitnesseKit/commit/c4e6c90a1f905e102c1fed8349c37f5d103442a7

I don't know why. After modifying the code, I always use MVN clean package to compile restfixture again.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.