It's very slow to test datastore api in cloud in my country, I hope a way to test datastore code in local. so I found following code:
package ro.gae
import com.google.appengine.tools.development.testing.LocalDatastoreServiceTestConfig
import com.google.appengine.tools.development.testing.LocalServiceTestHelper
/**
* Created by roroco on 8/23/15.
*/
trait LcDatastore {
LocalServiceTestHelper h = new LocalServiceTestHelper(new LocalDatastoreServiceTestConfig());
def iiLcDs() {
h.setUp()
}
def closeLcDs() {
h.tearDown()
}
}
But above code only save records in memory, and these records will disappear after code finish. I hope a way to save records in my disk to simplify my code
update
I hope the way don't need to start dev_server since dev_server need a long startup in java
did you try something like this?
public class MyTestClass {
LocalServiceTestHelper localServiceTestHelper;
#BeforeClass
public void beforeClass(){
LocalDatastoreServiceTestConfig localDatastoreServiceTestConfig = new LocalDatastoreServiceTestConfig();
localDatastoreServiceTestConfig.setBackingStoreLocation("storagefilelocation");
localDatastoreServiceTestConfig.setNoStorage(false);
localServiceTestHelper = new LocalServiceTestHelper(localDatastoreServiceTestConfig);
}
#Test
public void testSomething(){
}
}
edit: By the way, I aggree with #Igor Artamonov that this is very likely a bad idea. It should work though. I can also think of a few things that this could help with; like importing huge datasets into the dev local storage by running a unit test (or any external application).
Related
I have been experiencing something really weird. Maybe someone can explain me where I am making mistake.
I have a following scenario in a feature file
#DeleteUserAfterTest
Scenario: Testing a functionality
Given admin exists
When a user is created
Then the user is verified
My #After method in Hooks class looks like following
#After
public void tearDown(Scenario scenario) {
if (scenario.isFailed()) {
final byte[] screenshot = ((TakesScreenshot) driver)
.getScreenshotAs(OutputType.BYTES);
scenario.embed(screenshot, "image/png"); //stick it in the report
}
driver.quit();
}
I am using the following method in my step definition to delete the created user based on tag passed in the Test Scenario as follows:
#After("#DeleteUserAfterTest")
public void deleteUser(){
//Do fucntionalities to delete user
}
My test runner looks something like this:
import io.cucumber.testng.AbstractTestNGCucumberTests;
import io.cucumber.testng.CucumberOptions;
#CucumberOptions(
plugin = {"pretty","com.aventstack.extentreports.cucumber.adapter.ExtentCucumberAdapter:", "json:target/cucumber-report/TestResult.json"},
monochrome = false,
features = "src/test/resources/features/IntegrationScenarios.feature",
tags="#DeleteUserAfterTest",
glue="Steps")
public class IntegrationTest extends AbstractTestNGCucumberTests {
}
However, when I launch the test case, sometimes my user is deleted in the After("#DeleteUserAfterTest") but sometimes my test does not recognises the tagged After at all. It directly goes to After method in my Hooks class and quits the driver. Maybe someone has encountered this problem or knows a workaround!
Method order is not defined in Java. So you have to tell Cucumber in which order you hooks should be executed. Higher numbers are run first (before hooks are the other way around).
#After(order = 500)
public void tearDown(Scenario scenario) {
}
#After(value = "#DeleteUserAfterTest", order = 1000)
public void deleteUser(){
}
I am working with JADE framework and I want to know is there any way for intelligent agents to work with some kind of data base, where they can read from it and write some information?..
I tried to make a connection between excel (using jxl) and my project but there is a problem: below is the code for writing in excel file:
public static void write(String[] args) throws Exception {
// TODO code application logic here
File f = new File("C:\\Users\\Mastisa\\Desktop\\Master.xls");
WritableWorkbook Master = Workbook.createWorkbook(f);
WritableSheet History_Table = Master.createSheet("History_Table", 0);
Label L00 = new Label (0,0,"RUN#");
History_Table.addCell(L00);
Master.write();
System.out.println("finished...");
Master.close();
}
}
but I want agents to do something like this:
Database D;
D.add(myAgent.getLocalName);
but it is not possible as jxl doesn't provide functions for working with agents. and it looks like that everything must be written in that excel file manually.... but it is not what I want.. I want agents comfortably read and write...
Is there any other way?
Yes basically when you create a JADE agent, you can add behaviors to those Agents,
There are several types of behaviors, you should be choosing them based on your requirement. You can find the list of behaviors here
For an Example,
public class MyAgent extends Agent
{
#Override
protected void setup()
{
addBehaviour( new InformBehaviour() );
}
private class InformBehaviour extends CyclicBehaviour
{
//dostuff
}
}
So basic idea is you need to do all these inside a behavior of a agent.
Make sure you choose right behaviour which suites your requirement.
I am trying to understand Unit testing and how the correct classes are being fetched on test time,
I'm having a hard time understanding exactly what is going on behind the scenes and how safe/correct my usages for this are.
This is a very simple example of what i am trying to do, i wrote it here inline so it probably contains some errors, please try to ignore them, as stupid as they may be.
A very simple project directory:
ba/src/main/java/utils/BaUtils.java
ba/test/main/java/utils/BaUtilsTest.java
notBa/src/main/java/im/BaObj.java
BaUtils.java code:
package com.ba.utils;
import notBa.im.BaObj;
public class BaUtils{
public String doSomething(BaObj obj){
obj.doSomething();
}
}
I would like to test BaUtils wihtout actually calling doSomething, and i can't change anything on BaObj class or notBa package. I know that i can (by 'can' i mean it will work) add a new java file to 'ba' project (ba/test/java/notBa/main/java/im/BaObj.java) that will have the same package as the original BaObj, and at runtime the test will import this one instead of the real one, so BaUtils code is tested but BaObj code is not excecuted.
that should look something like like :
package notBa.im.Baobj
public class BaObj{
public void doSomething(){
System.out.println("Did something");
}
}
My questions are (And thank you for reaching this far):
How does this work (Reading references would be great).
Is this kind of test building considered 'good' or 'safe' ?
Thanks!
The solution is to use a mocking framework (I for myself like Mockito).
The test would look like this:
class BlaUtilTes{
#Rule
public MockitoRule mockitoRule = MockitoJUnit.rule();
#Mock
Blaobj blaobj;
#Test
public void doSomething_WithMockedBlaobj_callsDosomethingOnBlaobj(){
// arrange
BlaUtil blaUtil= new BlaUtil();
// act
blaUtil.doSomething(blaobj);
// assert
Mockito.verify(blaobj).doSomething();
}
}
find more information here http://www.vogella.com/tutorials/Mockito/article.html#testing-with-mock-objects
Your BaUtilsTest class should look like this.. I have used mockito for for mocking external dependencies. Also I changed the method return type to String for easy understanding.
#RunWith(MockitoJUnitRunner.class)
class BaUtilsTest {
BaUtils util;
#Mock
BaObj mockBaObj;
#Before
public void setup() {
util = new BaUtils();
}
#Test
public void testDoSomething() {
Mockito.when(mockBaObj.doSomething()).thenReturn("did the work using mock");
String result = util.doSomething(mockBaObj);
Assert.assertEquals("did the work using mock", result);
}
}
I am new at Play! 2.1. I'm trying to TDD my database integration test. After reading the examples on the website. I wrote my test like this.
#Test
public void shouldGetDealName() {
running(fakeApplication(), new Runnable() {
public void run() {
List books = Book.find.all();
Assert.assertEquals(books.size(), 1);
}
});
}
My question would be, do I need to wrap the code in running(fakeAppliation()... all the time? Because if I run this code without the fakeApplication. It doesn't seem to work. If it has to be like that then is there a better way to do this in Java? It seems wrong for me to wrap the code in that block every time for integration or functional test.
Thanks.
You can do it this way, assuming you want to use in-memory DB and you want it to be recreated for each test:
public class ApplicationTest extends WithApplication {
#Before
public void setup() {
start(fakeApplication(inMemoryDatabase(), fakeGlobal()));
}
#Test
public void shouldGetDealName() {
List books = Book.find.all();
Assert.assertEquals(books.size(), 1);
}
}
I have written simple java program:
package bsh;
import test.Testclass;
public class Whatever {
public static void main(String args[]){
Testclass t = new Testclass();
System.out.println(t.squareIt(8));
}
}
package test;
public class Testclass {
public Testclass(){
}
public int squareIt(int i){
return i*i;
}
}
I have two questions about this java program:
How to execute this java program from jmeter?
How to call sqaureIt(int i) method from jmeter?
How can i achieve this?
I haven't tried main class execution , but i have certainly executed Junit Testcases through Jmeter
Have a look at this doc Junitsampler tutorial
Aside from following the tutorial as Sudhakar mentioned...
Your main test case must extend TestCase or some form of it. Your test method must begin with the word test or use annotations.
Do not use a void main method as in a normal java application.
It will automatically call and run your method that starts with the name test.
So you could do this:
public class Whatever extends TestCase {
public void testIt() {
//test code here
new Testclass().squareIt(5);
}
}
JMeter is typically used for testing performance on web applications. Correct me if I'm wrong, but unless you plan on converting this into some sort of web app, you should try using VisualVM to measure your program's performance.