Testing CodenameOne business logic using JUnit - junit

I want to write the business logic of my CodenameOne application using JUnit 5. But when I try to run any unit test in Intellij, the simulator is started with the app instead of the unit tests.
Did anybody figure out how to setup Intellij such that the unit tests can be run without triggering the Ant build?

Codename One has its own unit test API and test recorder, generally you should use that for your testing as it allows you to test everything including the GUI.
See this for further details on using the testing framework.
You could probably use JUnit for the pure business logic but I'm not sure what benefit it would provide.

Related

JUnit 5 vs TestNG

We were using JUnit 4, but we had some problems with test grouping. For integration tests we had problems with running order. We had migrated to TestNG in February 2016.
Now we are starting a new independent module for our project and part of our team players wants JUnit 5. I believe it is much better than 4th (there are some new important features, but I see some problems too).
I do not want to use JUnit 5 because of fear of possible problems in our new application, because I have experience with 4th. But I have to be more flexible for the team, so before making a decision I need recommendations from users who have experience with JUnit 5.
TestNG objective is beyond unit test so it covers wider testing needs like Scenario Tests, Integration Test, Dependency Test, Ordering, Parallel Execution etc, but these feature are not supported in JUnit 5.
The JUnit 5 team have these above items in their road map, but they are extending a unit testing framework to support wider range of testing needs. Lets see how the new subsequent release of Junit 5 is able to address the wider testing need in comparison with TestNG
For Spring based application Junit fits best for doing the Unit and Integration Testing as it the default testing framework and Spring Provides lots of Test API with Mockito.
For general testing and Web Automation (Selenium) - TestNG is the de facto.
JUnit 5 introduced a lot of new features. Currently Intellij IDEA supports JUnit 5.
Take a look at article about integrating: Using JUnit 5 in IntelliJ IDEA.
There are some useful annotations now, like:
#Tag Used to declare tags for filtering tests, either at the class
or method level; analogous to test groups in TestNG or Categories in
JUnit 4
#DisplayName Declares a custom display name for the test class or test method
See more: JUnit 5 User Guide

Running TestNg tests via JUnit TestSuite

Is it possible to execute TestNg tests in a JUnit TestSuite. I see a lot of web pages describing how to use TestNg to run JUnit but none the other way around.
No, only JUnit tests can be run in TestNG.
TestNG was initially developed as a replacement for JUnit with additional functionality and an emphasis on smooth migration. An ability to run JUnit tests was one of the tools for that smooth migration.
TestNG fully covers the functionality of JUnit and adds something new. And JUnit can not (currently?) emulate that difference in functionality.
You may check the comparison of these two libraries here.

Good Unit Testing Options in FlashDevelop

I'm new to AS3 and Flex, but I am creating a mobile app with them in FlashDevelop. I want to add some unit tests, but I can't find any really good frameworks or documentation on it. I saw a little bit on FlexUnit and AsUnit, but both seem to be a few years old, and there isn't much documentation on using them in FlashDevelop.
Is there a good framework I can use for unit testing here? Even if I can't test the UI layer, I'd like to at least make sure my backend functions work correctly.
If you are testing backend functions, then you generally want to use the testing framework of whatever backend you are using. If you want Flex to test your backend functions, then you aren't Unit Testing, you are Integration Testing. While FlexUnit seems old, it still performs well at serving its purpose. The usage of FlexUnit should be independent of your IDE, you may just have to do more typing.
You can try to use the Flexunit4.0 for testing the business logic on the client side mixing it with the Mockito. None of these actually support testing the UI.
i've never tried to test the backend services with the Unit testing because of the authentication issues, but we created another testing UI for testing the services, This UI has a tons of screens, each screen to test different services.
I've seen that there is a ServiceBrowser for amfphp, i'm not sure if this can be used for Java or other platforms.
Other ways of testing the UI is by automation testing, use flexmonkey, selenium for that.

writing Test cases for restful service using junit

i have been given a project to write test cases for restful service using junit. The restful service provides json data as output.I am new to this, although i have attained basic knowledge but still do not know what to test.Please help.
Ok. So there are several things that could / should be done.
Unit test the Controller directly. Mock all other classes.
Attempt to use any framework provided testing utilities to test how the controller interacts with the framework. An example of this is Spring's MockMVC. For an example, check out the "correct" answer to this question: JUnit test for ExceptionHandler
Both of the above to not require a deployed service to test and so work well in the test phase of maven.
Additionally, although this would be an integration test, you could write JUnit tests using RestTemplate to hit the running service and verify the results. Since this has the external dependancy that the service is deployed and doesn't use any mocks it is an integration test. That said, it is a very valid set of tests and can be written in JUnit. However, these tests should be named (or categorized) as Integration tests so that they can be isolated from the tests that do not have external dependancies.
The fact that the service provides JSon should not be a big deal. Just use Jackson to unmarshal it into a domain object and verify the values are what you expect.
Send request and test the response. You may use restfuse.

WSO2 JUnit/Integration Testing

I'm in the process of building a Carbon Archive using the new WSO2 Developer Studio. I'm trying to work out how I can wrap the components (Sequences/Proxies etc) in JUnit tests. These tests will need to run as part of a CI build process (Jenkins) in order to detect errors with any modified code. I've done some research and can't seem to find anything that immediately stands out on how to achieve this. I did find this link https://wso2.org/jira/browse/TOOLS-855
which suggests that it hasn't yet been implemented. Can anyone confirm when this will be implemented or if there is any way at present to achieve this?
There is currently no straight forward way to implement this scenario and this feature will be supported in a future version.
One mechanism i can think is that, add a separate Test module as a part of the build which executes after building C-Apps.
So what happens in here is that, first Jenkins produce the CAR file for C-Apps. Then Maven start executing the JUnit test suite. Before the execution of Test Suite, you can configure maven to copy the CAR files to Servers and start up server. Then execute the Test Cases against the started up server.
This way you can deploy the new CAR files in your Carbon Server and execute the tests against the new configuration in the Server.
Thanks and Regards,
Harshana