Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
52 changes: 51 additions & 1 deletion BUILDING.txt
Original file line number Diff line number Diff line change
Expand Up @@ -603,7 +603,57 @@ NOTE: Cobertura is licensed under GPL v2 with parts of it being under

test.verbose=false

(7.5) Running httpd integration tests
(7.5) Running tests by profile

Tomcat provides named test profiles for running curated subsets of tests
without specifying file patterns manually.

Available profiles:

smoke - Core smoke tests covering key subsystems
catalina - All Catalina servlet container tests
coyote - All Coyote protocol/connector tests
tribes - All Tribes clustering tests
performance - Performance benchmark tests
buildutil - Build utility tests (excluded by default)
integration - httpd integration tests (excluded by default)

Usage:

ant test -Dtest.profile=smoke
ant test -Dtest.profile=catalina

Profile membership is declared via @Category annotations directly on test
classes. CategoryScanner discovers matching tests at build time by scanning
compiled classes and feeds the result into the standard Ant batchtest
mechanism so each test still runs in its own JVM.

(7.5.1) Adding a test to a profile

Annotate the test class with the appropriate category and add the
corresponding import:

Profile Category class
------- --------------
smoke SmokeTest
catalina CatalinaTest
coyote CoyoteTest
tribes TribesTest (also add CatalinaTest for catalina coverage)
performance PerformanceTest
buildutil BuildutilTest
integration IntegrationTest

Example — adding a test to the catalina profile:

import org.junit.experimental.categories.Category;
import org.apache.tomcat.categories.CatalinaTest;

@Category(CatalinaTest.class)
public class MyNewTest { ... }

All category interfaces are in the org.apache.tomcat.categories package.

(7.6) Running httpd integration tests

Tomcat includes integration tests that verify Tomcat's behavior when
running behind an Apache HTTP Server (httpd) reverse proxy. These tests
Expand Down
84 changes: 52 additions & 32 deletions build.xml
Comment thread
vgosain-psg marked this conversation as resolved.
Resolved
Original file line number Diff line number Diff line change
Expand Up @@ -1998,56 +1998,53 @@

<!-- ==================== Test Profile System ==================== -->
<!--
Property-based test profiles for convenient, selective test execution.
Annotation-based test profiles for convenient, selective test execution.

Usage: ant test -Dtest.profile=<profile-name>

Precedence: test.entry > test.profile > default
If test.entry is set, the profile is ignored to maintain backward compatibility.

Profile patterns are defined in test-profiles.properties test.profile properties
to keep this file readable.
Profile membership is declared via @Category annotations on test classes.
CategoryScanner discovers matching tests at build time by scanning compiled
classes, so no separate file list needs to be maintained.
-->

<!-- ================= Initialize Test Profile Property Values ================ -->

<!-- We read test profile definitions from "test-profiles.properties.default" -->
<!-- and also from "test-profiles.properties" if it exists. -->
<!-- The values in "test-profiles.properties" have stronger preference. -->
<!-- If you want to customize your build, you can either change the values -->
<!-- directly in the default file, or create a new test-profiles.properties and -->
<!-- set the values there. This way you don't have to change a file which -->
<!-- is part of the original project source code. -->
<!-- See "test-profiles.properties.default" in the top level directory for some -->
<!-- property values you may customize. -->
<property file="${user.home}/test-profiles.properties"/>
<property file="test-profiles.properties"/>
<property file="test-profiles.properties.default"/>

<!-- Macro to set test pattern based on profile name -->
<macrodef name="set-profile-pattern">
<attribute name="profile"/>
<sequential>
<!-- Set test.name property based on the profile attribute -->
<condition property="test.name" value="${test.profile.smoke}">

<!-- All profiles are now annotation-driven. Record the category class so
that the -test-categories target (which runs after test-compile) can
invoke CategoryScanner and set test.name. -->
<condition property="test.category.class"
value="org.apache.tomcat.categories.SmokeTest">
<equals arg1="@{profile}" arg2="smoke"/>
</condition>
<condition property="test.name" value="${test.profile.catalina}">
<condition property="test.category.class"
value="org.apache.tomcat.categories.CatalinaTest">
<equals arg1="@{profile}" arg2="catalina"/>
</condition>
<condition property="test.name" value="${test.profile.coyote}">
<condition property="test.category.class"
value="org.apache.tomcat.categories.CoyoteTest">
<equals arg1="@{profile}" arg2="coyote"/>
</condition>
<condition property="test.name" value="${test.profile.performance}">
<condition property="test.category.class"
value="org.apache.tomcat.categories.PerformanceTest">
<equals arg1="@{profile}" arg2="performance"/>
</condition>
<condition property="test.name" value="${test.profile.tribes}">
<condition property="test.category.class"
value="org.apache.tomcat.categories.TribesTest">
<equals arg1="@{profile}" arg2="tribes"/>
</condition>
<condition property="test.name" value="${test.profile.buildutil}">
<condition property="test.category.class"
value="org.apache.tomcat.categories.BuildutilTest">
<equals arg1="@{profile}" arg2="buildutil"/>
</condition>
<condition property="test.name" value="${test.profile.integration}">
<condition property="test.category.class"
value="org.apache.tomcat.categories.IntegrationTest">
<equals arg1="@{profile}" arg2="integration"/>
</condition>
</sequential>
Expand All @@ -2057,10 +2054,14 @@
<target name="-test-profile-init" if="test.profile" unless="test.entry">
<set-profile-pattern profile="${test.profile}"/>

<!-- Validate that the profile exists -->
<fail message="Unknown test profile '${test.profile}'. Check test-profiles.properties[.default] for available profiles.">
<!-- Validate that the profile exists: either test.name is set (pattern-based)
or test.category.class is set (category-based, test.name set later). -->
<fail message="Unknown test profile '${test.profile}'. Available profiles: smoke, catalina, coyote, performance, tribes, buildutil, integration.">
<condition>
<not><isset property="test.name"/></not>
<and>
<not><isset property="test.name"/></not>
<not><isset property="test.category.class"/></not>
</and>
</condition>
</fail>

Expand All @@ -2087,9 +2088,28 @@
<echo message="Test profile: ${test.profile}"/>
</target>

<!-- Set default test.name if no profile specified, using ant's immutability feature -->
<!-- Set default test.name if no profile or a pattern-based profile is in use.
Skipped for category-based profiles: test.name is set by -test-categories
after test-compile completes. -->
<target name="-test-name-default" depends="-test-profile-init">
<property name="test.name" value="**/Test*.java"/>
<property name="test.name" value="**/Test*.java" unless:set="test.category.class"/>
</target>

<!-- Scan compiled test classes for the category recorded by -test-profile-init
and populate test.name. Listed after test-compile in test-nio and
test-only-nio so that .class files are available; no compile dependency
here so that test-only can scan without recompiling. -->
<target name="-test-categories" if="test.category.class">
<java classname="org.apache.tomcat.categories.CategoryScanner"
outputproperty="test.name"
Comment thread
vgosain-psg marked this conversation as resolved.
Resolved
fork="true"
logError="true"
failonerror="true">
<classpath refid="tomcat.test.classpath"/>
<arg value="${test.category.class}"/>
<arg value="${test.classes}"/>
<arg value="${basedir}/test"/>
</java>
</target>

<!-- ==================== End of Test Profile System ==================== -->
Expand Down Expand Up @@ -2139,13 +2159,13 @@
</target>

<target name="test-nio" description="Runs the JUnit test cases for NIO. Does not stop on errors."
depends="-test-name-default,setup-jacoco,test-compile,deploy,test-openssl-exists,test-tcnative-exists" if="${execute.test.nio}">
depends="-test-name-default,setup-jacoco,test-compile,deploy,-test-categories,test-openssl-exists,test-tcnative-exists" if="${execute.test.nio}">
<runtests protocol="org.apache.coyote.http11.Http11NioProtocol"
extension=".NIO" />
</target>

<target name="test-only-nio" description="Runs the JUnit test cases or NIO without test preparations. Does not stop on errors."
depends="-test-name-default,setup-jacoco,test-openssl-exists,test-tcnative-exists" if="${execute.test.nio}">
depends="-test-name-default,setup-jacoco,-test-categories,test-openssl-exists,test-tcnative-exists" if="${execute.test.nio}">
<runtests protocol="org.apache.coyote.http11.Http11NioProtocol"
extension=".NIO" />
</target>
Expand Down
104 changes: 0 additions & 104 deletions test-profiles.properties.default

This file was deleted.

4 changes: 4 additions & 0 deletions test/jakarta/el/TesterCompositeELResolverPerformance.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,15 @@
package jakarta.el;

import org.junit.Test;
import org.junit.experimental.categories.Category;

import org.apache.tomcat.categories.PerformanceTest;

/*
* This is an absolute performance test. There is no benefit it running it as part of a standard test run so it is
* excluded due to the name starting Tester...
*/
@Category(PerformanceTest.class)
public class TesterCompositeELResolverPerformance {

/*
Expand Down
4 changes: 4 additions & 0 deletions test/jakarta/el/TesterImportHandlerPerformance.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,15 @@
package jakarta.el;

import org.junit.Test;
import org.junit.experimental.categories.Category;

import org.apache.tomcat.categories.PerformanceTest;

/*
* This is an absolute performance test. There is no benefit it running it as part of a standard test run so it is
* excluded due to the name starting Tester...
*/
@Category(PerformanceTest.class)
public class TesterImportHandlerPerformance {

/*
Expand Down
3 changes: 3 additions & 0 deletions test/jakarta/servlet/http/TesterHttpServletPerformance.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,18 @@
import jakarta.servlet.ServletException;

import org.junit.Test;
import org.junit.experimental.categories.Category;

import org.apache.catalina.connector.RequestFacade;
import org.apache.catalina.filters.TesterHttpServletResponse;
import org.apache.tomcat.categories.PerformanceTest;


/*
* This is an absolute performance test. There is no benefit it running it as part of a standard test run so it is
* excluded due to the name starting Tester...
*/
@Category(PerformanceTest.class)
public class TesterHttpServletPerformance {

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,15 @@
import jakarta.servlet.jsp.TesterPageContext;

import org.junit.Test;
import org.junit.experimental.categories.Category;

import org.apache.tomcat.categories.PerformanceTest;

/*
* This is an absolute performance test. There is no benefit it running it as part of a standard test run so it is
* excluded due to the name starting Tester...
*/
@Category(PerformanceTest.class)
public class TesterScopedAttributeELResolverPerformance {

/*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,16 @@
import java.util.function.Supplier;

import org.junit.Test;
import org.junit.experimental.categories.Category;

import org.apache.tomcat.categories.PerformanceTest;
import org.apache.tomcat.unittest.TesterThreadedPerformance;

/*
* This is an absolute performance test. There is no benefit in running it as part of a standard test run so it is
* excluded due to the name starting Tester...
*/
@Category(PerformanceTest.class)
public class TesterContainerProviderPerformance {

@Test
Expand Down
Loading