Skip to content
Closed
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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package org.apache.maven.surefire.its;

/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

import org.apache.maven.surefire.its.fixture.SurefireJUnit4IntegrationTestCase;
import org.junit.Test;

import static org.apache.commons.lang3.JavaVersion.JAVA_1_8;
import static org.apache.maven.surefire.its.fixture.HelperAssertions.assumeJavaVersion;

/**
* Basic suite test currently only running against JUnit 5 M2
*
* @author <a href="mailto:britter@apache.org">Benedikt Ritter</a>
*/
public class JUnit5IT
extends SurefireJUnit4IntegrationTestCase
{

@Test
public void test()
{
assumeJavaVersion( JAVA_1_8 );

unpack( "/junit5" ).executeTest().verifyErrorFree( 2 );
}

}
77 changes: 77 additions & 0 deletions surefire-integration-tests/src/test/resources/junit5/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Licensed to the Apache Software Foundation (ASF) under one
~ or more contributor license agreements. See the NOTICE file
~ distributed with this work for additional information
~ regarding copyright ownership. The ASF licenses this file
~ to you under the Apache License, Version 2.0 (the
~ "License"); you may not use this file except in compliance
~ with the License. You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing,
~ software distributed under the License is distributed on an
~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
~ KIND, either express or implied. See the License for the
~ specific language governing permissions and limitations
~ under the License.
-->

<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>org.apache.maven.plugins.surefire</groupId>
<artifactId>junit5</artifactId>
<version>1.0-SNAPSHOT</version>
<name>Test for JUnit 5</name>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>1.8</java.version>
<junit.jupiter.version>5.0.0-M2</junit.jupiter.version>
<junit.vintage.version>4.12.0-M2</junit.vintage.version>
<junit.platform.version>1.0.0-M2</junit.platform.version>
</properties>

<dependencies>
<dependency>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the first IT.
I should study what these dependencies mean :)

<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>${junit.jupiter.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
<version>${junit.vintage.version}</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
</configuration>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>${surefire.version}</version>
<dependencies>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-surefire-provider</artifactId>
<version>${junit.platform.version}</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package junit5;

/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;

/**
* A test using the JUnit 4 API, which should be executed by JUnit vintage enigne
*/
public class JUnit4Test
{

private boolean setUpCalled;

private static boolean tearDownCalled;

@Before
public void setUp()
{
setUpCalled = true;
System.out.println( "Called setUp" );
}

@After
public void tearDown()
{
tearDownCalled = true;
System.out.println( "Called tearDown" );
}

@Test
public void testSetUp()
{
Assert.assertTrue( "setUp was not called", setUpCalled );
}

@AfterClass
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing BeforeClass and assertion statement that it was called. If the around methods are not invoked by junit, the assertions would not fail. WDYT?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I copied this test from the /junit-4 directory. We probably have to fix that test also.

public static void oneTimeTearDown()
{
Assert.assertTrue( "tearDown was not called", tearDownCalled );
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package junit5;

/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;


/**
* A test using the JUnit 5 API, which should be executed by JUnit jupiter enigne
*/
public class JUnit5Test
{

private boolean setUpCalled;

private static boolean tearDownCalled;

@BeforeEach
public void setUp()
{
setUpCalled = true;
System.out.println( "Called setUp" );
}

@AfterEach
public void tearDown()
{
tearDownCalled = true;
System.out.println( "Called tearDown" );
}

@Test
public void testSetUp()
{
Assertions.assertTrue( setUpCalled, "setUp was not called" );
Copy link
Contributor

@Tibor17 Tibor17 Sep 8, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's up to your taste:)
I like using static import because especially in the assertion statements are verbose and if you read them in whole line then it sounds like sentence you read in news, very narrative. And therefore the class name does not have meaning to make it more verbose, it's just only a place where the function is stored.
The line width is limited to 120 chars which forces me to decide on how to type complete statement without breaking the line and without wrapping with nested call.

}

@AfterAll
public static void oneTimeTearDown()
{
Assertions.assertTrue( tearDownCalled, "tearDown was not called" );
}

}