junit

@IfProfileValue not working with JUnit 5 SpringExtension

大城市里の小女人 提交于 2021-02-08 13:19:38
问题 I use junit5 with spring-starter-test, in order to run spring test I need to use @ExtendWith instead of @RunWith . However @IfProfileValue work with @RunWith(SpringRunner.class) but not with @ExtendWith(SpringExtension.class) , below is my code: @SpringBootTest @ExtendWith({SpringExtension.class}) class MyApplicationTests{ @Test @DisplayName("Application Context should be loaded") @IfProfileValue(name = "test-groups" , value="unit-test") void contextLoads() { } } so the contextLoads should be

@IfProfileValue not working with JUnit 5 SpringExtension

Deadly 提交于 2021-02-08 13:19:31
问题 I use junit5 with spring-starter-test, in order to run spring test I need to use @ExtendWith instead of @RunWith . However @IfProfileValue work with @RunWith(SpringRunner.class) but not with @ExtendWith(SpringExtension.class) , below is my code: @SpringBootTest @ExtendWith({SpringExtension.class}) class MyApplicationTests{ @Test @DisplayName("Application Context should be loaded") @IfProfileValue(name = "test-groups" , value="unit-test") void contextLoads() { } } so the contextLoads should be

“folder has not yet been created” error when using JUnit temporary folder in testclass

回眸只為那壹抹淺笑 提交于 2021-02-08 13:11:18
问题 I get the error "the temporary folder has not yet been created", which comes from an IllegalStateException thrown by the TemporaryFolder.getRoot() method. It looks like it's not initialized, but my research showed me that this is usually the case when the temp folder is initialized in setUp()-method. But using it with @Rule like I did should work in my opinion. Any ideas? The test class public class FileReaderTest extends TestCase { @Rule public TemporaryFolder folder = new TemporaryFolder();

“folder has not yet been created” error when using JUnit temporary folder in testclass

只愿长相守 提交于 2021-02-08 13:04:25
问题 I get the error "the temporary folder has not yet been created", which comes from an IllegalStateException thrown by the TemporaryFolder.getRoot() method. It looks like it's not initialized, but my research showed me that this is usually the case when the temp folder is initialized in setUp()-method. But using it with @Rule like I did should work in my opinion. Any ideas? The test class public class FileReaderTest extends TestCase { @Rule public TemporaryFolder folder = new TemporaryFolder();

Partial Mocking on HttpSession

和自甴很熟 提交于 2021-02-08 04:15:02
问题 There is a servlet i want to test , servlet have session and puts "loginBean" (which contain logged in user related info) inside session , which i have mocked already and working fine , now IN GUI level , there are 2 tab , DetailSet1 , detailsSet2 , when u enter data of DetailSet1 , it get saved in session and also does some business logic , now it comes to DetailsSet2 , you already have DetailSet1 in session , so it got all it needs , data is saved in DB. Now it's obvious i have to mock

Partial Mocking on HttpSession

☆樱花仙子☆ 提交于 2021-02-08 04:11:59
问题 There is a servlet i want to test , servlet have session and puts "loginBean" (which contain logged in user related info) inside session , which i have mocked already and working fine , now IN GUI level , there are 2 tab , DetailSet1 , detailsSet2 , when u enter data of DetailSet1 , it get saved in session and also does some business logic , now it comes to DetailsSet2 , you already have DetailSet1 in session , so it got all it needs , data is saved in DB. Now it's obvious i have to mock

Mocking SecureRandom::nextInt()

安稳与你 提交于 2021-02-08 01:57:37
问题 I have a class that uses a SecureRandom instance and grabs the next random number. Lets say the example is: public class ExampleClass() { public void method() { Random sr = new SecureRandom(); System.out.printf("%d %n", sr.nextInt(1)); System.out.printf("%d %n", sr.nextInt(1)); } } Test code @RunWith(PowerMockRunner.class) public class ExampleClassTest { ... @Test @PrepareOnlyThisForTest(SecureRandom.class) public void mockedTest() throws Exception { Random spy = PowerMockito.spy(new

Mocking SecureRandom::nextInt()

試著忘記壹切 提交于 2021-02-08 01:57:04
问题 I have a class that uses a SecureRandom instance and grabs the next random number. Lets say the example is: public class ExampleClass() { public void method() { Random sr = new SecureRandom(); System.out.printf("%d %n", sr.nextInt(1)); System.out.printf("%d %n", sr.nextInt(1)); } } Test code @RunWith(PowerMockRunner.class) public class ExampleClassTest { ... @Test @PrepareOnlyThisForTest(SecureRandom.class) public void mockedTest() throws Exception { Random spy = PowerMockito.spy(new

Mockito Spy calls the actual method of the spied class instead of returning the hardcoded mock

对着背影说爱祢 提交于 2021-02-07 20:01:32
问题 Here's my Spy statement OAuthService oAuthServiceMock = Mockito.mock(OAuthService.class); Mockito.doReturn(oAuthServiceMock).when(inviteServiceSpy.buildOAuthService(RESOURCE_URL, CONSUMER_KEY, CONSUMER_SECRET)); Here's the method in the actual class public OAuthService buildOAuthService(String RESOURCE_URL, String CONSUMER_KEY, String CONSUMER_SECRET) { return new ServiceBuilder() .provider(new DummyOAuth1ApiProvider(RESOURCE_URL)) .apiKey(CONSUMER_KEY) .apiSecret(CONSUMER_SECRET)

Mockito Spy calls the actual method of the spied class instead of returning the hardcoded mock

我只是一个虾纸丫 提交于 2021-02-07 20:01:24
问题 Here's my Spy statement OAuthService oAuthServiceMock = Mockito.mock(OAuthService.class); Mockito.doReturn(oAuthServiceMock).when(inviteServiceSpy.buildOAuthService(RESOURCE_URL, CONSUMER_KEY, CONSUMER_SECRET)); Here's the method in the actual class public OAuthService buildOAuthService(String RESOURCE_URL, String CONSUMER_KEY, String CONSUMER_SECRET) { return new ServiceBuilder() .provider(new DummyOAuth1ApiProvider(RESOURCE_URL)) .apiKey(CONSUMER_KEY) .apiSecret(CONSUMER_SECRET)