Questions tagged [junit5-extension-model]

1

votes
0

answer
7

Views

TempDirectory extension: is there a replacement for createInCustomDirectory() methods?

There used to be createInCustomDirectory() methods in TempDirectory extension class in JUnit 5.4.0-M1 (see docs). The main use case for those methods was to change tmp dir used by the extension. In the final release (5.4.0) TempDirectory extension was made private and enabled by default and those me...
Andrey Pechkurov
2

votes
0

answer
17

Views

Extension lifecycle and state in JUnit 5

User guide contains following: Usually, an extension is instantiated only once. It's not very clear when extension can be instantiated many times? I'm supporting test suite with multiple extensions and every extension stores it's state in class fields. Everything works fine, but can I rely on this o...
Sergey Guriev
3

votes
1

answer
511

Views

JUnit 5, pass information from test class to extension

I am trying to write an extension for Junit5 similar to what I had for Junit4 but I am failing to grasp how to do that in the new (stateless) extension system. The idea in the previous version was that user could pass information into extension class and hence change the way it behaved. Here is a ps...
Siliarus
2

votes
5

answer
1.3k

Views

JUnit5 - How to get test result in AfterTestExecutionCallback

I write JUnit5 Extension. But I cannot find way how to obtain test result. Extension looks like this: import org.junit.jupiter.api.extension.AfterTestExecutionCallback; import org.junit.jupiter.api.extension.TestExtensionContext; public class TestResultExtension implements AfterTestExecutionCallback...
bugs_
2

votes
1

answer
210

Views

How to create custom JUnit5 Extensions

Is it possible to create a custom extension like I could've created a @Rule in JUnit4? public class MockMetadataServiceRule extends ExternalResource { @Override protected void before() throws Throwable { //some setup } @Override protected void after() { // some teardown } } Then, I can do this wi...
LazerBanana
4

votes
3

answer
207

Views

Check that JUnit Extension throws specific Exception

Suppose I develop an extension which disallows test method names to start with an uppercase character. public class DisallowUppercaseLetterAtBeginning implements BeforeEachCallback { @Override public void beforeEach(ExtensionContext context) { char c = context.getRequiredTestMethod().getName().charA...
Roland Weisleder
4

votes
2

answer
71

Views

What is the equivalent of @RuleChain in JUnit 5?

I have 2 "class level" rules : MyRule1 and MyRule2 MyRule2 depends on MyRule1 MyRule1 "before" method should therefore run before the MyRule2 "before" method. In JUnit 4, it can be implemented this way, via the RuleChain : static MyRule1 myRule1 = new MyRule1(); static MyRule2 myRule2 = new MyRule2(...
Baptiste Le Bail