My jar won't add my junit tests - eclipse

The contents of my jar file does not contain my junit tests. I tried creating a main class that calls my tests with "Junit Core" but that too doesn't get added to my jar file. What am I missing?

Your production package (your jar) is not supposed to contain the test code (your unit tests).
Test code is supposed to be invoked only when the tests are been executed.
You shouldn't do it, but if you want the test code to be included in your package just put it in the same root folder of your production code. Ex: if you are using Maven, your folders structure might be something like this:
project_name/src/main/java/
-> production code
project_name/src/test/java/
-> test code
In that case, change it to:
project_name/src/main/java/
-> production code
-> test code
Be aware that doing that you will have some problems, like the tests not executing during a normal build. We might help you better if you put a question asking how to accomplish your goal (what is your goal?).
Update based on the goal explained in the comments: Would be better if this tool (Silk Central) could run your tests using Maven or Ant, and I'm pretty sure it can.
I've been used different tools to run my Junit (or other XUnit frameworks) tests. What I do is to configure the tool to:
Get the source code from the version control.
Run the build/tests by calling Maven or Ant installed along the tool.
Read the Junit outputs.
Sometimes the tool has its own integration with Junit and you don't have even to use Maven or Ant.
I mean, your central build or tests tool should be able to run your tests just like you do in your own machine.
Take a look on this or search by "Silk Central junit" in the web:
http://community.microfocus.com/borland/test/silk_central/w/wiki/465.zero-maintenance-junit-testing-using-classpathsuite-in-sctm.aspx

Related

SBT/Scala and Integration testing

While researching on the subject of automating my integration tests, I found out a nice plugin in the maven world called FailSafe. it gives me phases like pre-integration-test, post-integration-test and integration-test.
By tying into these phases, I can have other plugins which can start/stop and run docker images.
The plugin also has a nice way in which I can differentiate between UnitTests and IntegrationTests (even though both are written in JUNIT).
Well now the question is how can I do the same thing with Scala / SBT combination?
my requirement is
Write Integration tests in SpecFlow.
Integration tests are treated differently than unit tests.
First Unit Tests are run.
Then docker containers are created and run
then integration tests are run.
docker contains are shut-down.
test results are captured in files. (just like surefire/failsafe plugins).
Is this possible in Scala/sbt combo?
A simple solution is to run $ sbt "~ it:test" (make sure integration test are in a package named 'it') for integration test which will automatically run every time source code is updated. Furthermore, $sbt "~ test" for automated unit testing. If you are using a IDE such as IntelliJ IDEA, you can make it easier to run this in a custom configuration from the IDE. Hope this helps a little bit. I run these all the time when working.
I found the answer to the question. SBT provides means to do integration test and also setup and cleanup methods to do things like creation / destruction of docker containers
http://www.scala-sbt.org/0.13/docs/Testing.html

Using Maven for JUnit testing

I started learning JUnit testing within Eclipse. The plugin that is used to show the test results presents a nice clean view of the test and you can click on items that take you to the areas in code that are under test.
When I started working with Maven, I noticed that you can have Maven carry out your JUnit tests as well. However, because Maven is a command line process and the results get written to the console, the JUnit results get sent there as well. And it looks like crap. You have to parse your way through all the console text to find the results of the test. Everything is just plain old text.
This raises the question as to what purpose Maven has in testing with JUnit (or any other test frameworks for that matter)? I must be missing the point. Why would anyone want to read a large text dump when the Eclipse plugin provides an elegant way of viewing, executing and evaluating tests?
Generally speaking, you build on the command line because you've got everything working correctly in your IDE. The command line build is the final sanity check and possibly the way in which you are releasing your software (e.g. mvn release:perform etc.).
While there are a few plugins that make Maven test output slightly nicer, the expectation is that the tests will pass. If they don't, fire up Eclipse and run the tests again.
Maven is a build tool. Its goal and purpose is to produce repeatable and protable result. This is especially important when we talk about build/continuous integration servers.
So the normal workflow is/should be: Developers usually develop using their IDE (eclipse), they run their tests in the IDE, because it is developer centric and more comfortable.
The build server, lacking a graphical environment runs the build tool, i.e. maven.
Sometimes, the results between maven and the eclipse might differ, in that case might become necessary for developers to also run maven on their machine.
Another reason to use maven directly might be integration test which specifically us maven lifecycle integrations for say starting and stopping a server.
Some specific points: Maven quite comfortably shows you which tests failed in a summary:
00:46:21.988 Results :
00:46:21.988
00:46:21.988 Failed tests:
00:46:21.988 MyTest.testPersistErrorStateNewTransaction:48 Test for 'testPersistErrorStateNewTransaction()' not yet implemented!
00:46:21.988
00:46:21.988 Tests in error:
00:46:21.988 MyOtherTest.testMethod
00:46:21.989
00:46:21.989 Tests run: 1162, Failures: 1, Errors: 1, Skipped: 491
00:46:21.989
00:46:22.003 [ERROR] There are test failures.
00:46:22.004
Also, when run, from maven, you can still open the results of the surefire tests in your eclipse junit view by double-clicking on a test result (.xml) in the surefire-reports directory.
what purpose Maven has in testing with JUnit?
Unit testing is one of the part in Application Development(usually do while coding/developing components), Apache Maven is the project management tool, (as Duncan told) it helps us to releasing software.
includes - Dependency Management, Module Management, Plugin Management, and reporting configuration for tests.
Maven Objectives:
Making the build process easy
Providing a uniform build system
Providing quality project information
Providing guidelines for best practices development
Allowing transparent migration to new features
please look at below threads for more details about Maven:
Why do so few people use Maven?
Why maven ? What are the benefits?
Why would anyone want to read a large text dump when the Eclipse plugin provides an elegant way of viewing, executing and evaluating tests?
For software release purpose we need maintain statistics of the application(how many scenarios covered, test cases passed..etc). Maven supports different plugins to format the results, Maven Surefire Plugin, maven-site-plugin..etc plugins help us to generate reports different formats.
please refer below threads for more details:
JUnit3 and Junit4 XML Reports with Maven
Is there a decent HTML Junit report plugin for Maven?

How do I create a self contained package of Selenium JUnit Tests?

I have a bunch of Selenium Tests which I currently run on JUnit from Eclipse. (Using the Firefox webDriver)
I need to create an easy to install/use package of these tests to give to various members of the QA team so they can run them on different computers.
Is there something that already does this, is there a way to zip up eclipse + tests so they can be run from any computer?
Yes there are a couple of ways
I use maven for managing the project dependencies and run the tests via sure-fire plugin... but it looks like an overkill for your case
You can see a simple explanintion here:
how to export (JUnit) test suite as executable jar

Beginner: How to do JUnit tests on GWT application?

I want to preform a JUnit tests on my application. I've never done JUnit testing before so I have a couple of (maybe trivial) questions:
Where should I put a test class? I came across with this thread:
Where should I put my JUnit tests?,
and the guy that answers the question is referring to maven projects, but I don't use maven. He explains (in the thread I linked above) that he puts the test class in a different location but in the same package. How can it be done in a GWT project?
How should I execute these tests once they are ready (where in the code to put the execution)?
You should begin by reviewing this: Unit Testing GWT Applications with JUnit.
The other thread is good and reflects the typical JUnit practice, and isn't specific to maven: use a mirror of your package tree under a directory called test. So for instance if your GWT EntryPoint module is located in this directory structure:
project/src/com/myproject/mypackage/MyEntryPoint.java
Then your test code will be here:
project/test/com/myproject/mypackage/MyEntryPointTests.java
If you've created your GWT project using webAppCreator then you should already have a test directory containing the package structure as described.
If you use webAppCreator to create your project, the project can be created with unit testing built-in like so:
webAppCreator -junit -out MyProject com.myproject.mypackage.MyEntryPoint
This will create a test target. If you're using Eclipse, then you should have a Run selection for: Run As -> GWT Unit Test for running your tests.
If you're using ant instead of Eclipse then this should run your unit tests:
ant test
If you didn't use -junit to create the project, the test targets are typically still there, just commented out. Search junit in build.xml to find the targets, and un-comment them.
You need to take a look at this article, MVP1 and MVP2, these are a pattern designs used to Unit Test your application in pure java environment, because using GWT Test Case runs very slow the patterns also has many advantages like separate the logic from the view so you can change the view for Android, for example.

jUnit 4 DirectorySuiteBuilder Equivalent

I'd like to know if there is something similar to junit-addons DirectorySuiteBuilder (documentation) that works with jUnit 4. Simply stated, I want to load every file name *Test.java in a directory and build a suite out of them.
I realize that I can build a suite that runs every test in a directory using ant, but I would prefer to not go that route so that I can run the tests with eclipse's native jUnit plugin.
Sure enough, al nik. I don't know why I didn't think of that.