junit

AspectJ + Junit + Maven - pointcut recognized in tests but NoSuchMethodError: aspectOf() exception thrown

房东的猫 提交于 2019-12-18 13:14:28
问题 I have followed almost all JUnit + Maven + AspectJ questions here and even I am pretty sure I have everything set properly, I am unable to test it. I have a Maven module with just one aspect: @Aspect public class AssertionAspect { @Pointcut("execution(@org.junit.Test * *())") public void testMethodEntryPoint() {} @Before("testMethodEntryPoint()") public void executeBeforeEnteringTestMethod() { System.out.println("EXECUTE ACTION BEFORE ENTERING TEST METHOD"); } @After("testMethodEntryPoint()")

RESTful Services test with RestTemplate

牧云@^-^@ 提交于 2019-12-18 13:13:39
问题 In my application I have a lot of REST- Services. I have written tests for all services with: org.springframework.web.client.RestTemplate A REST- Service invokation e.g. looks like this: final String loginResponse = restTemplate.exchange("http://localhost:8080/api/v1/xy", HttpMethod.POST, httpEntity, String.class) .getBody(); and I check the response body afterwards - all works fine. The disadvantage is, that the application for sure must be started in order to invoke the REST- Services. My

Unit tests with Android Studio and Gradle?

纵饮孤独 提交于 2019-12-18 13:12:55
问题 How can I add unit tests to my Android projects in Android Studio (IntelliJ) easily? To be more exact: I want to add a folder with test code (JUnit 4) and execute the unit tests from there using the regular installed JDK (not in an Android emulator). So far I added the folders 'test/java/' to my module and added 'test' as a source set and junit as a test dependency: sourceSets { instrumentTest.setRoot('src/test') } dependencies { instrumentTestCompile 'junit:junit:4.+' // ... } When I now

Java jUnit: Test suite code to run before any test classes

落爺英雄遲暮 提交于 2019-12-18 12:49:26
问题 I have a test suite class: @RunWith(Suite.class) @Suite.SuiteClasses({ GameMasterTest.class, PlayerTest.class, }) public class BananaTestSuite { What annotation do I need to use to make a function in this class run before any of the classes containing actual tests? Right now, I'm doing this, and it works, but it's not as readable as it could be: static { try { submitPeelAction = new Player(new GameMaster(1)).getClass().getDeclaredMethod("submitPeelAction"); } catch (SecurityException e) { e

JUnit: @Before only for some test methods?

孤街浪徒 提交于 2019-12-18 12:45:13
问题 I have some common set up code that I've factored out to a method marked with @Before . However, it is not necessary for all this code to run for every single test. Is there a way to mark it so the @Before method only runs before certain tests? 回答1: Just move out the tests that don't need the setup code into a separate test class. If you have some other code common to the tests that would be helpful to keep, move that out into a helper class. 回答2: Or use TestNG. It gives you finer grained

How to test a Grails Service that utilizes a criteria query (with spock)?

混江龙づ霸主 提交于 2019-12-18 12:32:48
问题 I am trying to test a simple service method. That method mainly just returns the results of a criteria query for which I want to test if it returns the one result or not (depending on what is queried for). The problem is, that I am unaware of how to right the corresponding test correctly. I am trying to accomplish it via spock, but doing the same with any other way of testing also fails. Can one tell me how to amend the test in order to make it work for the task at hand? (BTW I'd like to keep

Need help installing JUnit on Mac/How to add JUnit to Path environmental variable on Mac OSX

梦想与她 提交于 2019-12-18 12:26:29
问题 I am not able to figure out how to correctly install JUnit onto my mac. I know I am supposed to add it to the path environmental variable, and I have tried a few tutorials I've found on Google on how to do that, but I keep getting errors. This is the link to the tutorial I have used: http://hathaway.cc/post/69201163472/how-to-edit-your-path-environment-variables-on-mac-os-x I have a feeling I am doing something wrong in step 3. I have placed the junit.jar file in the Library folder by the way

HowTo Unit Test Client Server Code

风格不统一 提交于 2019-12-18 12:12:15
问题 I'm currently writing a Java Client Server Application. So i want to implement two Libraries, one for the Client and one for the Server. The Client Server Communication has a very strict protocol, that I wan't to test with JUnit. As build tool im using Maven and a Husdon Server for continues Integration. Actually I do not have any good Idea how to test these Client / Server Libraries. I got following Approaches: Just write a Dummy Client for testing the server and write a Dummy Server to test

Ordering unit tests in Eclipse's JUnit view

为君一笑 提交于 2019-12-18 12:05:15
问题 The JUnit view in Eclipse seems to order the tests randomly. How can I order them by class name? 回答1: As Gary said in the comments: it would be nice if Unit Runner could be told to go ahead and order them by class name. Hmm, maybe I should look into the source code... I did look but there's no hint of a functionality to sort these names. I would suggest a change request to the JUnit plugin, but I don't think, that there are lot of people using this thing, so: DIY. I would like to see the

TestNG dependsOnMethods from different class

☆樱花仙子☆ 提交于 2019-12-18 11:47:35
问题 The dependsOnMethods attribute of the @Test annotation works fine when the test to be depended upon is in the same class as that of the test that has this annotation. But it does not work if the to-be-tested method and depended-upon method are in different classes. Example is as follows: class c1 { @Test public void verifyConfig() { //verify some test config parameters } } class c2 { @Test(dependsOnMethods={"c1.verifyConfig"}) public void dotest() { //Actual test } } Is there any way to get