Creating Java test rules - java

I will start to create a Java project from eclipse which will contain all Java tests to control GUI.
When I create project I have :
TestProject\
.\src
.\Jre system library
Are there configuration rules?
Could I put all Java files in the same package under src and run configuration for each Java test?
Are there rules, documentation to help user to configure and create Java projects?
Thanks

If you are using JUnit, you may find some guidance in the FAQ Organizing Tests.
Addendum: Using your Eclipse Help > Help Contents menu, search for "JUnit" to see details of how to set up test. As an example, here's a link to an older version.

Related

How to setup allure for selenium +TestNG+java project?

I used extent report with java selenium for the automation testing but I would like to try allure reporting. Can anyone please explain to me how to setup Allure+ TestNG+ selenium in eclipse for automation?
Does it supports only maven based projects or even for java projects as well we can do it? Thanks
There is no pom.xml file in my current java project ...so this is a doubt if I can implement
It's fairly simple. If you don't have a pom that means you are possibly using ant to build your tests. That's not an issue. What you can do is, download the allure .jar file. Add it to your project and off you go. With allure, there is no setup required. You will, however, need to implement annotations in your classes where you would like allure yo log things.
Here is an example :
Allure will then log your tests and steps as you would suspect natively. If you want screenshots and all the other goodies you would need to implement it. The docs can help with this part.
Here is the link to the jar file for allure - https://jar-download.com/artifact-search/allure-testng
Have a nice day!
If you are not using pom, then based on latest version which is available at the time you need following JAR files to be added in build path of your project in eclipse .
In my example I would be using version 2.9.0
allure-testng-2.9.0.jar
allure-model-2.9.0.jar
allure-java-commons-2.9.0.jar
allure-descriptions-javadoc-2.9.0.jar
sl4j-api-1.x.x.jar
Finally you need allure-commandline-2.9.0.zip .choose same version which you have downloaded above files.
Extract and set the path as described in the link -https://docs.qameta.io/allure/#_manual_installation
Hope It helps! Thanks

How do i link a compiler to an editor

So i have tried to find an answer but didn't manage to do it yet. What I'm trying to do is to write a Java code for example in Atom editor, and compile it on Atom itself, without the need of an integrated development environment. Same goes with adding classes to a project.
Is that possible?
Yes. That is how they wrote the first Integrated Development Environments. Although the compilation step is typically performed externally from the editor, if the editor can execute external programs then you can "integrate" compilation. Adding "classes" is a little more involved, in that it requires your "editor" to understand the packaging and structure of the files composing the classes - at that point you have an integrated development environment.
Yes it's possible with atom package build. To install the package Edit-->Preferences-->Install and type build and hit Enter. Then you should configure your custom build command as mentioned in official package website. You may just fill cmd: javac in yml file for example
You need to install a package that will compile. Atom is a hackable text editor but not really an IDE as you pointed out. That said there are a lot of packages for compiling and for working with java.
You can look at Build Tools Package for compiling. It looks like it will work for Java but there are many compilers in the package list.
I would search on their package site for the keyword "Java" to see what java packages you might want to use. Then do another search for "Compile" to see what compiler you might want to use if the build tool above doesn't work for you. You can search atom packages at https://atom.io/packages.

Using custom Java classes in Clojure REPL

In Eclipse, using the CCW plug-in, I want to load a clojure file into a REPL. The problem is that I have an import statement for one of my own java classes, but apparently it is not in my classpath.
(ns my-clj-ns
(:import [alg.gen Enumerator]))
Do I have to make jars out of every class that I want use/test in a Clojure REPL?
Currently, trying to load my clj into a REPL results in an error:
"Load file in Clojure REPL" did not complete normally. Please see the log for more information.
java.lang.NullPointerException
Any help would be greatly appreciated.
You can let leiningen compile these for you using,
:javac-options {:destdir "classes/"}
:java-source-path "src/main/java" ; location of Java source
options or manually compile them and move the class files to the classes/ directory. No need to create a jar.
When you're in the ccw repl, you can hit alt-e to see the stack trace. If you're getting a NullPointerException, I don't think its a classpath issue.
Your code looks fine to me.
I suspect the issue is with your Eclipse Java Build Path, which determines what Eclipse includes in the classpath for your application.
In particular, if your Java class is in a separate project, you will need to either add that project to the build path (right click on project / Properties / Java Build Path / Projects) or package it as a jar.
When you start to have more sophisticated build requirements, you may also want to start looking at Maven to handle this kind of thing for you. Maven is a pain to learn / set up in the first place but it pays of in the long run.
Leiningen is also a great tool to use but I personally don't use it for the following reasons:
It is great on the command line, but doesn't integrate so nicely with an Eclipse workflow
Maven is more widely used and better supported in the Java world
There is really nice guide if you want to learn how to do this.
https://github.com/technomancy/leiningen/blob/master/doc/MIXED_PROJECTS.md
But in gist, have a project definition like the following for Java source code.
(defproject megacorp/superservice "1.0.0-SNAPSHOT"
:description "A Clojure project with a little bit of Java sprinkled here and there"
:source-paths ["src/clojure"]
:java-source-paths ["src/java"])

Implement Growl in Java Application

I want my Java application to make a growl notification. My IDEs are Eclipse and Netbeans, and I am trying to implement a library in either (so far it worked it neither). How can I just add the library to my project and then reference the classes from within my own classes? Moreover, where can I find an appropriate library?
Thanks in advance!
EDIT: Ok, now I have somehow managed to implement the library ^^ However: the following command fails:
System.loadLibrary("growl");
It returns following error:
Message: no growl in java.library.path
How can I fix this?
About an appropriate library you should just google it. I found this one (that is tested on 10.5 so maybe it will need some tweaks): http://www.cocoaforge.com/viewtopic.php?f=6&t=17320
To add the library to your project in Eclipse copy it into the project folder (this is not necessary, you could just copy it wherever you want, also in extension folder of the JDK) and then add it through the project settings:
open project properties by right clicking the project and choosing Properties
go to Java Build Path option
go to Libraries and add it
It's possible to use AppleScript script engine in Java 6 on OS X to communicate with Growl. Here's a blog post describing how to do it.
You can use the network binding like in https://github.com/chamerling/JavaGrowl or https://github.com/aerofs/growljavabindings
Maybe this can help you.
If your classes are packaged in a JAR file, just like a 3rd party library, you should be able to put it in your project /lib directory and add it to the CLASSPATH using the IDE. That should be all you have to do (if I understand your question correctly).

Tool for creating Dynamically Generated Code in Java (In Eclipse)

In Visual Studio land, I used to be able to define a structure in an XSD file and add a special attribute to it which would cause it to be dynamically compiled and available to use with intellisense in the other C# files in the application. I am not sure exactly what the term for this is, perhaps "dynamic code generation."
I am trying to accomplish the same in Java using Eclipse IDE. Basically what I am looking for is a tool that will allow me to specify some template and generate Java code from it in a "hot folder" that will allow me code complete in the other static Java files.
Does anyone know of a solution for this? I know it is possible in Visual Studio, but I can't seem to find anything for Eclipse.
Ok, here is exactly what I want to do.
Step 1. I create a folder called templates
Step 2. I create a file called HelloWord.ibes
Step 3. Code it automatically generated in my src folder HelloWorld.java
I want to be able to do this in eclipse easily.
You may create an ant build file that does the source generation for you. Then you are free to use any code generator you like. Ant support is part of the eclipse IDE. If you prefer maven, there's a nice eclipse pluging available (that's what I actually use for source code generation based on jaxb, javacc and xdoclet...).
Technically spoken, you just add another eclipse builder which is invoked anytime eclipse detects a change in your code base.
If you already have a code generator in mind, just 'ask' the internet if there's a plugin available.
Edit
On how to install a builder: This is done automatically. For maven, you just install the maven plugin (m2eclipse) and enable maven dependencies for a project. Then if you look at the projects properties pages (Builder section), you find a second entry in the list of builders.
It's similiar with ant, even easier, because ant is already integrated. "enable" ant for a project and the builder is added to the list of builders for the project. You can deselect it at any time if it kills performance or switch of automatic building (I don't know by heart how to enable ant builds for a project, but I remember that the eclipse help had sufficiant informations).
All about ant can be found here: Apache Ant
Creating a new builder is difficult, as it has to be coded in java and added to eclipse as a plugin. I bet you don't want to follow that track ;)
I'm not sure whether you have seen the code template option?
Preferences.Java, Code Style then Code Templates
How
to add code templates
Useful
code templates

Categories

Resources