GithubHelp home page GithubHelp logo

junit5-demo's Introduction

Demos for JUnit 5

This is a sample application that demonstrates the core features of JUnit 5, especially the JUnit Jupiter programming model.

In addition, demos are provided for using the Spring TestContext Framework from the Spring Framework as well as testing support in Spring Boot.

The following technologies are used.

  • JUnit Platform 1.5.2
  • JUnit Jupiter 5.5.2
  • JUnit Vintage 5.5.2
    • which includes JUnit 4.12 (for comparison with JUnit Jupiter)
  • Spring Framework 5.2 GA
  • Spring Boot 2.2 RC1
  • Gradle 5.6.2
  • Java 12

Note

Some of the tests intentionally fail in order to demonstrate support for assertAll() (i.e., grouped assertions) in JUnit Jupiter vs. the lacking support for grouped assertions in JUnit 4. Additional tests intentionally fail to demonstrate the functionality of the @SkipOnFailuresInEnclosingClass extension.

junit5-demo's People

Contributors

sbrannen avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

junit5-demo's Issues

Missing the Jupiter platform configuration

Your code snippet, is missing the Jupiter platform configuration in the build.gradle file. Because of this when running gradle test tests are not actually picked up.

Add
test { useJUnitPlatform() }
for the project to be fully valid, even when build is run from the command line.

Possible bug in this with spring boot usage

@sbrannen I'm working on converting mybatis-spring-boot over to junit 5 and the legacy rule version of this was used. Since it doesn't appear spring / spring boot is going to pick up full junit 5 support for some time with numerous tickets in last month stating as much on these more complicated concerns, I think I'm left to use your library directly in mybatis code base. By itself this works great! However, I'm running into a problem most likely in where logs are logged with spring boot. As I've seen you all over the place through my research I was hoping you might be able to pinpoint my issue.

Here is a test I'm attempting to run

@CaptureSystemOutput
@ExtendWith(SpringExtension.class)
@SpringBootTest
public class SampleMybatisApplicationTest {

	@Test
	void test(OutputCapture outputCapture) {
		String output = outputCapture.toString();
		assertThat(output).contains("1,San Francisco,CA,US");
	}

}

By the time @test is executed on the first line, spring boot has already output to the console a lot of information as follows.

[INFO] Running sample.mybatis.SampleMybatisApplicationTest

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::        (v2.0.7.RELEASE)

4730 [main] WARN  o.m.s.mapper.ClassPathMapperScanner - Skipping MapperFactoryBean with name 'cityMapper' and 'sample.mybatis.mapper.CityMapper' mapperInterface. Bean already defined with the same name!
5110 [main] DEBUG s.m.mapper.CityMapper.findByState - ==>  Preparing: select * from city where state = ?
5115 [main] DEBUG s.m.mapper.CityMapper.findByState - ==> Parameters: CA(String)
5123 [main] TRACE s.m.mapper.CityMapper.findByState - <==    Columns: ID, NAME, STATE, COUNTRY
5123 [main] TRACE s.m.mapper.CityMapper.findByState - <==        Row: 1, San Francisco, CA, US
5124 [main] DEBUG s.m.mapper.CityMapper.findByState - <==      Total: 1
1,San Francisco,CA,US

So I'd expect this to work but simply get the following

Expecting:
 <"">
to contain:
 <"1,San Francisco,CA,US">
        at sample.mybatis.SampleMybatisApplicationTest.test(SampleMybatisApplicationTest.java:40)

I suspect this has more to do with logback usage in spring boot than anything else. I attempted to mess around with it's configuration to force console out but that didn't seem thave any effect. Any pointers would be greatly appreciated. I've even tried to use the junit 5.3.2 support for getting at the system out through TestExecutionListener but have had the exact same results.

Unable to get the TestResults using @testDisabled, @testFailed, @testSuccessful and @testAborted

Hi,
Thanks for the sample and youtube presentation :)
I am using springboot with gradle along with Junit5. I am trying to use TestWatcher to perform certain actions on failure of a test case. However, the @testDisabled, @testfailed, @testSuccessful and @testAborted do not get invoked. I tried adding a print statement to the testDisabled and @testfailed functions and they did not get printed. I have tried the same on your project junit5-demo (in SkipOnFailuresInEnclosingClassExtension.class) but it does not reach the @testDisabled/@testfailure functions. Can you please suggest on it? My intension is to perform certain actions based on the test result. I also tried using @ExtendWith(SkipOnFailuresInEnclosingClassExtension.class) in the test but could not get it working. Could please suggest on it?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.