Schlagwörter: TeamCity Kommentarverlauf ein-/ausschalten | Tastaturkürzel

  • Andreas Höhmann 15:03 am Thursday, 26. November 2009 Permalink |
    Tags: , , , TeamCity,   

    Concept to handle minimal and maximal tests in a maven project 

    In real world applications we have all too often external dependencies in test cases. Sometimes theses third party are not always available (i.e. remote webservices).

    For continuous integration I want check a minimal set of tests but for my local development i want check a maximal set of tests. I want run my tests on command line (via maven) and in eclipse (via testng-plugin).

    Here is my idea to do that …

    My project super pom defines 2 profiles:

    • test-min
      1. active by default
      2. exclude testng groups (online-tests, thirdparty-tests,…)
    • test-max
      1. run a defined testng suite
      2. the suite defines a maximal set of test (all testng groups)
    <profiles>
      <profile>
        <id>test-min</id>
        <activation>
          <activeByDefault>true</activeByDefault>
        </activation>
        <build>
          <plugins>
            <plugin>
              <artifactId>maven-surefire-plugin</artifactId>
              <inherited>true</inherited>
              <configuration>
                <excludedGroups>${excludedTestGroups}</excludedGroups>
              </configuration>
            </plugin>
          </plugins>
        </build>
      </profile>
      <profile>
        <id>test-max</id>
        <build>
          <plugins>
            <plugin>
              <artifactId>maven-surefire-plugin</artifactId>
              <inherited>true</inherited>
              <configuration>
                <suiteXmlFiles>
                  ${basedir}/src/test/resources/Testsuite.xml
                </suiteXmlFiles>
              </configuration>
            </plugin>
          </plugins>
        </build>
      </profile>
    </profiles>
    <properties>
      <excludedTestGroups>online,integration,thirdparty</excludedTestGroups>
    </properties>
    

    Each subproject must define a testng src/test/resources/Testsuite.xml:

    <!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
    <suite name="TestSuite for Foobar">
      <test name="Online Tests">
        <packages>
          <package name="de.foobar.*" />
        </packages>
        <groups>
          <run>
            <include name="online" />
          </run>
        </groups>
      </test>
      <test name="Integration Tests">
        <packages>
          <package name="de.foobar.*" />
        </packages>
        <groups>
          <run>
            <include name="integration" />
          </run>
        </groups>
      </test>
      <test name="Thirdparty Tests">
        <packages>
          <package name="de.foobar.*" />
        </packages>
        <groups>
          <run>
            <include name="thirdparty" />
          </run>
        </groups>
      </test>
      <!-- Each project can define MORE groups: i.e. "interactive" -->
      <test name="Other Tests">
        <packages>
          <package name="de.foobar.*" />
        </packages>
        <groups>
          <run>
            <exclude name="online" />
            <exclude name="integration" />
            <exclude name="thirdparty" />
            <!-- Each project can define MORE groups: i.e. "interactive" -->
          </run>
        </groups>
      </test>
    </suite>
    

    If the sub project defines more exclude groups (i.e. a additional “interactive” group) then the pom must overwrite the excludedTestGroups property:

    <properties>
      <excludedTestGroups>online,integration,thirdparty,interactive</excludedTestGroups>
    </properties>
    

    To check the correct configuration of the two profiles we can use help:effective-pom:

    mvn -Ptest-min help:effective-pom | less

    <plugin>
      <artifactId>maven-surefire-plugin</artifactId>
      <configuration>
        <excludedGroups>online,integration,thirdparty,interactive</excludedGroups>
      </configuration>
    </plugin>
    

    mvn -Ptest-max help:effective-pom | less

    <plugin>
      <artifactId>maven-surefire-plugin</artifactId>
      <configuration>
        <suiteXmlFiles>
          <suiteXmlFile>d:\foobar\src/test/resources/Testsuite.xml</suiteXmlFile>
        </suiteXmlFiles>
      </configuration>
    </plugin>
    

    Now I can run min/max tests for each project which depend on the above super-pom. The test-min is the default profile and would be used on the continuous integration system (i.e. TeamCity).

    Try it :)

     
    • Thomas Wabner 10:09 am Dienstag, 31. Januar 2012 Permalink | Zum Antworten anmelden

      Short info … the current 2.11 version of the surefire plugin contains a bug with the “excludeGroups” rule … you need to wait for 2.12 or just use 2.10.

  • Andreas Höhmann 18:33 am Wednesday, 20. August 2008 Permalink
    Tags: Build, Continuous Integration, , , Site, TeamCity, xdoc   

    Show TeamCity Buildstatus in Maven Projectsite 

    Today i will show you a little hack for TeamCity and Maven. At the end you will be able to show the last (live!) buildstatus of your artifact on the generate project-site.

    Lets define a new menu-item “status” in our project-site-descriptor (src/site/site.xml):

     ...
      <menu name="Overview" inherit="top">
      <item name="Introduction" href="index.html" />
      <item name="Status" href="status.html" />
      </menu>
     ...
    

    Hint: you can do this in your parent-project, so all subproject will inherit this menu.

    Now we must define the status.xml (src/site/xdoc/status.xml):

    <?xml version="1.0" encoding="UTF-8"?>
    <document>
      <properties>
        <title>Buildstatus</title>
      </properties>
      <body>
        <section name="Status">
          <div id="statuswidget"/>
        </section>
        <script type="text/javascript">
        <![CDATA[
          //
          // url to the team-city-server
          // define HOST, PORT and BUILDID
          //
          var url = 'http://HOST:PORT/externalStatus.html'
                   + '?buildTypeId=BUILDID'
                   + unescape( '%26' )   // "hide" amp
                   + 'withCss=true';
          var container = document.getElementById('statuswidget');
          var iframe = document.createElement('iframe');
          iframe.style.width  = '100%';
          iframe.style.height = '500px';
          iframe.style.border = 'none';
          container.appendChild(iframe);
          iframe.doc = null;
          if(iframe.contentDocument)
            iframe.doc = iframe.contentDocument;
          else if(iframe.contentWindow)
            iframe.doc = iframe.contentWindow.document;
          else if(iframe.document)
            iframe.doc = iframe.document;
          iframe.doc.open();
          iframe.doc.close();
          iframe.doc.location.href=url;
        ]]>
        </script>
      </body>
    </document>
    

    Insert HOST and PORT. The BUILDID is the number of the build-configuration:

    Hint: The width of the iframe should be 100% but you can customize the height – so if you later click on the status-element you can show teamcity directly in you projectsite … cool :D

    Activate the status-widget for your build-configuration:

    Build the site:

    mvn clean site-deploy
    

    Now you have a new menu-item, click and you will see the TeamCity status for your artifact.

    The implementation details …

    The “normal” way to display the build-status (see TeamCity documentation) is shown here:

    <script type="text/javascript" src="<path_to_server>/externalStatus.html?js=1&amp;amp;buildTypeId=BUILDID">
    </script>
    

    But it’s not possible to insert this code in maven’s xdoc-format (there is no javascript-tag allowed!).
    So i found a solution to insert the teamcity-url into a dynamic created iframe. The second trick is to encode the “&” in the url (unescape(‘%26’)).

    Try it!

     
c
Neuen Beitrag erstellen
j
nächster Beitrag/nächster Kommentar
k
vorheriger Beitrag/vorheriger Kommentar
r
Antwort
e
Bearbeiten
o
zeige/verstecke Kommentare
t
Zum Anfang gehen
l
zum Login
h
Zeige/Verberge Hilfe
Shift + ESC
Abbrechen
Folgen

Erhalte jeden neuen Beitrag in deinen Posteingang.

Schließe dich 86 Followern an