Is it necessary to use gradle with roboelectric for android unit testing? - robolectric

I and my team have built up an android library project. it is built up on eclipse but we are using ant to build it. Presently we aren't using gradle. I have a roboelectric with dependencies jar file instead. But when I use this, while running the unit tests, the following error comes up
WARNING: multiple versions of ant detected in path for junit
[junit] jar:file:/Users/prateekarora/Desktop/eclipse/plugins/org.apache.ant_1.9.2.v201404171502/lib/ant.jar!/org/apache/tools/ant/Project.class
[junit] and jar:file:/Users/prateekarora/trunk/client/android/MCCMobileClient/test2/libs/robolectric-2.3-with-dependencies.jar!/org/apache/tools/ant/Project.class
When I remove the apache ant from eclipse's plugin folder, this stops working.
Can Anybody explain why this is happening?
Also, is it necessary to use roboelectric with gradle? If no, where can I find the roboelectric's jar files with/without dependencies?

It is not necessary to use gradle with robolectric. It is just about running specified java class (from junit) with proper classpath (including you source, test code and dependencies). Fixing your case is not something that is easy to make over stackoverflow (it will be some challenge even if you sit behind same computer).
Here are possible solutions:
Migrate your project build to the gradle
Keep using ant but move from dependency management from manuals jars to ivy
Keep using ant and manual jars dependency, but try to get robolectric.jar with all dependencies except ant one
The first one option is the easiest option as for me. It will require to change mindset a bit but this is officially only one supported build tool by Google as well there are a lot of examples and people that could help.
The second one also require you to learn how to use new tool. As well there less examples about ivy usage especially in android projects.
The third one will require to write custom script that removes ant from jar file or to rebuild robolectric-all.jar without one (ant) dependency. This will require to dive into maven build tool learning

Related

Can MR-Jars overwrite classes from other jars?

I have a jar that works on Java 8.
I would like to create a new jar, that is going to be Multi-Release JAR but empty, just with 'patched' classes in META-INF/versions.
I would like to have a separate jar, so people can include it on Java9, otherwise, they use the default one. Why? Because so many tools are not yet prepared for Java9 MR-Jars.
Would this be possible? Would Java9 MR-Jar override classes from others jars?
Why?
The idea behind Multi-Release jars is that they provide simple patching. In my humble opinion, the way MR jars works is not satisfying.
There are two reasons why I can't make 2 separate Jars:
try to make cross-compile source base that works with Java8 and Java9. You would end up with folders like java, java8 and java9... and then have the build produce two jars, two poms... Yeah, good luck.
Imagine that I even build a library for java9. What about transient dependencies? That would mean that all other libraries that uses mine, would need to have jre8 version that depends on my jre8 version. Just because there is Java9 version!
Here is the story:
My A is a Java library built on Java8 but packaged as Multi-Release Jar which means it contains additional classes for when jar is run on Java9. Additional classes are built separately on JDK9 and I copied them manually (yeah, I know, but it works for now).
Unfortunately, some tools and servers (Jetty) are not aware of MR Jars and this makes them NOT working.
For that reason, I have A-jre8 version of my library, that comes without any extra classes, so servers can use it.
However, if user is using library B that depends on my A, he will still get the MRJar version of A and this will fail again. I want to be able to prevent this somehow. And I can't say to B: hey, could you make B-jre8?
Possible solution
JAR is just about packaging!
Allow the separate jar to patch existing jar.
In my case, I would just include A.jar9 and Java would consider A.jar and A.jar9 together as a package. No need for META-INF/versions. Very clean. And, best of all, it would help in situations like above! If run on Java8, the jar9 jar would make no difference; if run on Java9 the jar9 jar would patch the jar with the same name. Simple as that. No transitive dependency hell.
Rename classes in META-INF/versions.
Common Oracle, have you ever heard about the classpath scanning? Could you at least rename the classes in versions to e.g. *.class9 so not to be caught by existing classpath scanners.
As it is today (Java v9.0.4) - no.

Stuck with creating Keyword library using Java in Eclipse and using that JAR file in RIDE

I'm new to ROBOT framework and must create library keyword using java and utilize the JAR files in RIDE editor. I have followed the below steps. But still have confusions in where to start up. Please help me to achieve this.
Steps:
1) Installed Python, wxPython, pybot, RIDE, selenium2library successfully and I'm able to work with RIDE using predefined keywords.
2) For creating own java library, Installed Eclipse Mars, Java, ROBOT IDE manually using the link https://github.com/NitorCreations/RobotFramework-EclipseIDE/wiki/Installation
The question here is,
Anything i'm missing to install?
How to proceed further with Robot Framework coding?
Note: I'm reading many materials in parts to proceed things. But that is confusing me what are the steps to be followed. Is there any single material that i can get having the sequences of steps that need to be followed for my requirements?
The below links I referred with,
https://github.com/NitorCreations/RobotFramework-EclipseIDE/wiki/Usage
Maven error "Failure to transfer..."
Create a Maven project in Eclipse complains "Could not resolve archetype"
http://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html#using-set-test-suite-global-variable-keywords
Let's start with the basics. RIDE is an editor for Robot Script files. Robot Script files are executed by the Robot Framework robot application. It is important to understand the difference between these two applications. One creates files and the other uses them.
Assuming for a moment here that you have some custom functionality in a Jar file that you would like to make available inside the Robot Script files test cases. If this is indeed the case then your focus should be on create Robot Test Libraries. In the documentation there are numerous java examples given for basing your own library on.
This means that you do not need Maven, unless you want to, to create your library. Also Eclipse IDE is not needed nor is RIDE. The library you create can be used by Robot Framework even when it's run from the command line. Feel free to use them for what they are good at: writing Robot Scripts efficiently and running Robot through menu options instead of command line windows.
When you are familiar with Eclipse and comfortable with it's features, then I can also recommend using the Eclipse Application RED which is a mature Eclipse add on for creating, running and debugging Robot scripts.
There are two ways of implementing a Java routine in Robot Framework and it depends a bit on how you run Robot Framework: Python or Jython. Running Python means that you need to run the Java in a separate JVM container and connect to it. The simplest way is via Command Line interaction. This may cause some security concerns. The second approach is to use the Remote Library approach. A good example of this is the Robot Framework Sikuli Library. An added bonus is that you can run Robot and your Java application on two separate machines/servers.
The Jython way has been discussed on StackOverflow before and I gladly refer to it. Please bear in mind that although the examples refer to RIDE, the Library org.company.Keywordlibrary works in all IDE's, provided robot framework is run using Jython.
In the Jython documentation it clearly explains how to setup an Eclipse based IDE with Jython. Do keep in mind that it's recommended to use the same interpreter in development and production. I.e. if you create your scripts in Jython, do run them in 'production' also using Jython. Otherwise you open yourself up to interpreter differences where functionality does not work or behaves differently then expected.
An alternative approach with Jython is the all-in-one Robot Framework Maven JAR plugin. Adding a custom Java Library in this setup is not too difficult. A nice short tutorial can be found on the blog of Valerio Bruno. If this is your preferred route for development, then you may want to read the RED howto on integrating the Robot Framework Maven jar.
Working on your custom functionality is likely going to be a independent project in Eclipse, but can be linked to an Robot project via the Class Path settings in red.xml if you use RED or the CLASS_PATH environment variable.
Done! I have installed RED and required add on using following below steps. It worked successfully with predefined keywords. Now I'm gonna create user defined keywords/libraries using the same editor. I don't know where to start up. Will it work creating just a java project? Should I need to include any additional libraries?
Steps followed to proceed with RED:
1. RED Version Conclusion: https://github.com/nokia/RED/blob/master/release.md
2. RED Installation Instructions: https://github.com/nokia/RED/blob/master/installation.md
3. ROBOT Framework prerequisites using RED: https://github.com/nokia/RED/blob/master/red_help/first_steps/download_install.html.md
4. To verify Installations in Eclipse: Help -> Installation Details to check if RED is visible on installed features list
5. Create Project and Tests using RED in Eclipse: https://github.com/nokia/RED/blob/master/red_help/first_steps/create_run.html.md
6. RED Steps: https://github.com/nokia/RED/blob/master/First_steps.md
7. Quick STart: https://github.com/nokia/RED/blob/master/red_help/user_guide/quick_start.html.md

Creating ant build script to build only when a dependency was updated

I just started working with ant a few days ago. Right now I have a general buildall.xml which should call each project's build.xml. Because some projects depend on each other, I need to rebuild some other projects which depend on it. This isn't a problem--I'm just setting the depends property of the target. However, ant is always building the dependencies, even when the files haven't changed.
Let's say project1 has no dependencies; project2 depends on project1; project3 depends on project1, 2; project4 depends on project1, 2, and 3; and so on.
I could hack a solution which looks at project K, and checks if project 1 .. project K have updated files using uptodate. If so, then run the target. This is messy and appears unnecessary.
What is the cleanest way to implement this?
EDIT: So I decided to just hack in a bunch of targets, "check_projectK" where it does the uptodate checks on all of its source files, its build file, and the build files of the 1 .. K-1 projects. Due to dependencies, this is always handled correctly. However, this is still a large amount of copy and paste for a large workspace. I will leave this open.
Short answer, ANT can't do it, not unless you have some kind of way to connect to your version control system and check if anything has changed (you are using source control right?). Ant doesn't know about when what the last time a file changed and then see if it matches with what was built; it doesn't have the concept of a dependency repository. The whole purpose of Ant is that it just builds.
The solution to your problem isn't Ant, it's Maven. Maven HAS a dependency repository. There's also a very nifty plugin for Maven used specifically with Flex appropriately called FlexMojos. By using this, Maven can know when something was last built because it's uploaded to the repository. Then your other projects can add it's dependencies and download the SWC needed.
On top of that, it mixes great with a continuous integration engine like Hudson, Bamboo and Teamcity, which builds a project every time a file has been committed to your source control system, and then updates all dependent projects automatically!

"Make" system for Actionscript?

In working on larger Actionscript/Flash projects, I've started to really feel the need for some kind of "make" system, but I haven't found it yet. Does anyone know if it exists?
Required features:
Ability to associate SWCs with their source code and/or FLAs i.e. "this swc is compiled from this source"
Ability to mark my current project as depending on these SWCs (either as compile-time or runtime libraries)
A single, big shiny button, that when pressed does the following:
Checks to see if any of the source files have changed, and if so, recompiles their associated SWCs
Recompiles and relinks the main .swf, if necessary
Runs the main .swf
Have yet to find a way to get something like FlashDevelop to do this (but I don't know it well enough to be sure). Support for both code and FLA sources is preferred.
You are looking for http://projectsprouts.org/ which is based on Rake the Ruby version of Make. It can do all of that stuff and much more.
If you have Ruby and RubiGems installed which I think are installed by default on Macs you can install it by typing this into your command line.
sudo gem install Sprout
It will take a while because it installs many things. After this is all set you can create a project like this.
sprout -n as3 ProjectName
and then build it with this,
rake deploy
It manges things based on the runtime they are created for, this project was created for as3 but all of the other types of projects also. The build scripts are all writen in Ruby and can be modified to involve more complex multi-step compiles pretty simply. It also has a bunch of generators so that classes automaticly have unit test that are associated with them and many other features.
Might be a stupid suggestion, but if you want make, why not just use "make"? You can use it for any language by defining the right rules.
Apart from that, I've seen a lot of Flex/Actionscript projects use Apache ant, an XML based build system.
As said by wump; why not use Make?
There are some ANT scripts included in the Flex SDK, so you could explore and expand those. I've also spoken to people who use Maven and Cruise Control for automated build process.
Here is some info on Maven Flex: http://code.google.com/p/flex-mojos/
And some info on Cruise Control w/ Flex: http://www.eyefodder.com/blog/2006/05/continuous_integration_with_fl_5.shtml
Well, there are several options. One I would recommend is the Maven plugin for Flex flex-mojos, now maintained on the Sonotype site. If Maven isn't your cup of tea, they do have an Ant plugin, I don't know if NAnt can call Java Ant tasks directly or not. The third is the most complicated, but Adobe does include an OEM version of the compiler, I believe it comes by default with the SDK download. This is the one I used in the Maven plugin I developed for my company. The reason we didn't use the flex-mojos one basically boils down to a...disagreement about the "Maven way" of one project = one artifact. Their interpretation is that 1 SWF file is one artifact, so is one Maven project. My definition for my project is that all 80+ modules, each a SWF file, are no different than JSPs, all bundled in the same WAR file. So I've got one project with a LOT of modules and 1 maven pom.
You could check out Antpile which according to said link "is a collection of Ant Scripts which cover everything from building a SWF, SWC, AIR, Android and even Unit Testing."

How do you enforce dependencies among java folders in Netbeans?

I am new to Netbeans. I am wondering if someone can help me with project setup in netbeans. I am moving half million lines of Java code from a different IDE to Netbeans. I was able to get the code build and run in Netbeans easily. I have a project with many folders with dependencies among those folders. They have to be built in specific order. This is to enforce layering so that a module in lower layer cannot call into higher layers. I couldn't get that configured in Netbeans. Below is how my project looks like
project/
libA/
libB/
libC/
libD/
libE/
appA/
...
I have one project that builds all the libs and appA. The project build xml is stored under project/ folder. But the libs have dependencies among them. libB should be built after libA. libC after libA. libE depends on libD and libB etc.
I tried to change the order of source folders for libs in project properties. That didn't seem to make any difference. Even if I move libA after libB, it was building everything fine. I expected it to fail because libA didn't build yet.
Iam lost. Just wondering what the trick is to enforce this kind of dependencies. I created my project using "Java project using existing sources" wizard.
I appreciate your help
Thanks
Video guy.
Even though it would be a pain, you could just write your own ant build script and then just have Netbeans use that.
Basically:
write the custom ant build file
install the Ant plugin
create an Ant build file
right click the build file
run the selected target.
This would enable you to enforce whatever you need to do, but, if Netbeans is figuring out the correct order then why not just use it.
Does something break when you just compile and run in Netbeans?
Well! Lets say a team member added piece of code in lower level package that calls into higher layer code. It should fail because it breaks the layering. Because Netbeans seem to compile all the files in one javac invocation, the build compiles just fine. I want Netbeans to break the build in this case.
Writing my own ant script is another way of enforcing it. The whole point in using an IDE is to save yourself from writing your own make files (or ant scripts). This is something any IDE was able to accomplish 10 years back out of the box. I am wondering if I am missing something here.
Thanks
Video Guy

Resources