I have an existing Java project set up in Intellij 12 and am attempting to add some Groovy classes to it. I've started with attempting to add a simple Spock class for testing purposes, but when I right-click on the class it does not give me an option to run it.
I've taken a look at my Intellij configuration and it pulls in groovy correctly. Further, I can write a Groovy script that uses a Groovy class and that runs without problems so it appears that Groovy is wired in. Is there something else I need to configure to specifically run Spock tests?
Easiest way to get spock and all dependencies is add library from maven.
Then, you should place your test in a folder, marked as test folder, if you want to allow batch processing of them.
If you place your script in folder, not marked as test, or source folder, you will be unable to run it.
If you can't see run button, it looks like Idea cannot recognise file as runnable, it isn't under source/test root, or it's extension is invalid.
You can add Spock plugin by:
Downloading the jar
In IDEA File->Settings->Plugins->Install from disk. Choose the jar.
I was having the same issue and ended up here. I found that I had forgotten to extend spock.lang.Specification. As soon as I did, the Run option showed up.
Just posting in case it helps any other Spock novices like myself.
Related
I have recently installed NB 7.3.1, and installed the JUnit plugin. In the old days, JUnit was bundled with NetBeans. I used it all that time.
I want to use it now, but I can't find any command, button, tool, etc to cause Netbeans to create the shell unit tests for me.
What am I doing wrong? How do I find it?
Thx
Make sure you have a test folder. Go to your project properties, and under Sources, in Test Package Folders, make sure you have at least one folder where you want to put your test sources.
If the button is still greyed out after that, you can go to File > New File > Unit Tests > JUnit Test. If it gives you an error message, it may help you solve the problem.
I have a main class that takes a series of arguments and I have 10 run configurations. Is there a way to have eclipse run them one after another?
The other answers are probably better solutions to your problem. However, if you install the Eclipse CDT into your Eclipse installation (using update manager or market place client), then you get an additional launch configuration type called Launch group.
Those launch groups allow creating a list of other launch configurations to be run one after the other. Make sure to set the Post build action in the dialog to "Wait until terminates" for each included launch configuration.
#Steven: To do it quick, you can write a JUnit Test case that just calls the intended classes in desired order and execute it. Eclipse already has the necessary jar for JUnit, so you are ready to go. Definitely, writing ANT/MAVEN script is a good practice.
As #gotuskar suggested, write test cases for your class. If you can afford running your ten configurations each time you build your project put them in its src/test/java directory, otherwise create a sibling project to your original one, make it depend on it, and put your tests there.
I was trying to create a Junit Testing framework within an existing RFT framework. The JUnit set up works fine to the point where we don't have to instantiate any framework classes.Whenever we are trying to access framework classes it throws the below exception. I did look for similar issues online but couldn't get a solution.Please suggest a solution if any body has faced a similar issue. RFT version is 8.1,JUnit version is 4
java.lang.NoClassDefFoundError: com.ibm.rational.test.lt.arm.IArmable
at java.lang.ClassLoader.defineClass(ClassLoader.java:265)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:69)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:521)
at java.net.URLClassLoader.access$300(URLClassLoader.java:66)
at java.net.URLClassLoader$ClassFinder.run(URLClassLoader.java:985)
I figured it out:
You have to add the jar "com.ibm.rational.test.lt.rftarm_8.2.1.v20120105_1832.jar" to your Java Build Path. Mine was located in C:/Program Files/IBM/IMShared/plugins/. It came with RFT, but appears to not have been included in the Build Path by default.
This looks like a classpath error. If you are invoking JUnit from ANT, Maven, or some similar build tool then make sure you have the appropriate JAR files in the classpath. Remember, some JARS in turn have their own dependencies. Unless all those dependencies are in the classpath you will get the java.lang.NoClassDefFoundError.
If you are trying to run from the GUI client, it might be a little more difficult. Essentially, you will have to add all the dependencies to the jvm's -classpath option.
I am new to java and to netbeans so my apologies if this is a simple question.
I made a 'Java Class Library' Project in Netbeans 6.9.1
I added a few classes to it and hit 'Build'. It builds with no errors. However the problem is I know there are errors.
It seems as though I can make up class names and hit build and it doesnt provide me with any feedback.
How can I make it so that netbeans validates my code when buildling a class library?
I am unable to 'run' the project becuase there is no Main. However this is a class library and I dont want to make test applications in my library.
Edit:
For example I can write the following and a 'clean & build' still works
MadeUpName x = new MadeUpName();
This will build even though I have no class or reference to a class that contains
MadeUpName
I also have no 'Import' statments as of yet and it still builds....
Thanks, stephanie
1) To test a Java Class Library project you should create another project and add your "Java Class Library" project as project dependency. In this new testing project you can write class with main method to test features of the class library. When you will build the test project NetBeans IDE will also build the class library project and will add the JAR file in the class path of the testing project.
2) If the Java Class Library projects compiles through "Clean & Build" that means the project has no syntax errors. That means your code may have logical errors which are not detected by the Java compiler. Usually class library developers create JUnit test cases to find out logical errors, and you are also strongly advised to use JUnit tests for your project.
with regards
Tushar Joshi, Nagpur
Ideally you should test a class library by writing unit tests (rather than test applications) that exercise the classes in your library. There are several unit-testing frameworks available that can help you write the unit tests. The most popular is JUnit.
The test cases should be placed in a different source folder in the same project as the code they are testing. When you build the project you should ensure that the test classes are not included in the JAR file. If you use a build tool like Maven it will do this for you as long as you follow it's project conventions.
Update
Based on your comments, and the fact that you tagged your question with Groovy, I'm guessing that the library is written in Groovy? Your problem seems to be that Netbeans doesn't perform the kind of type-checking that you get with Java (or other statically-typed languages)?
Because Groovy is a dynamic language, it's not possible for the compiler to perform the same rigorous type-checking that you get with Java, but at the very least the Netbeans Groovy editor should provide some hints/warnings if you're referencing classes that don't exist (for example). Are you sure you're opening the code in the correct editor (you may need to install a Groovy plugin first).
You should use GroovyTestCase, rather than JUnit directly to test a Groovy library.
If I'm looking at a class (MyComponent, say) somewhere underneath src/main/java in Eclipse, I can right click it and pick new...--> other --> JUnit test. Eclipse is smart enough to guess the name for the unit test class (MyComponentTest), but it insists on putting the unit test under src/main/java. Is there anything in Eclipse or m2Eclipse that can be set so that the default test location is src/test/java? Given that's the standard way of working with Maven, there has to be a setting for this somewhere but I can't find it.
Good question, this bothers me too. I googled it and found this suggestion: How to default the source folder for new JUnit tests in Eclipse?.
Basically it says: I use moreUnit, an Eclipse plugin to assist writing unit tests. Among other features, it lets you configure the default source folder of tests.
When creating a junit test, you can select another source folder than 'src/main/java'
if you click 'new > junit test' while having an other source-folder selected, it will use that one as the target.
so i guess there is no 'default' it just uses the 'current' folder. sensible defaults is not what eclipse is good at.
what is eclipse good at at all?