In KIF testing framework, in KIF acceptance class, can we create an instance of our controller class or model class to get the functions and views from that specific class? Or is the accessibility label the only way to identify the view? And if the latter is the only option, then how can we get access to our model class in KIF test class?
Yes. You can access anything in your host app.
Also, for your later choice, you can put a weak reference in your view to the model ..
But a notice is that, if you want to modify some static variable or access then, that bundle must be a singleton - Not two copies (one for test, one for app).
Related
I have copied full Random class from math.dart package, gave it CustomRandom name, and now I don't see why my code fails to work.
abstract class CustomRandom {
external factory CustomRandom([int seed]);
external factory CustomRandom.secure();
int nextInt(int max);
double nextDouble();
bool nextBool();
}
I'm using it like
print("${Random().nextInt(10)}"); // standard one works
print("${CustomRandom().nextInt(10)}"); // my one fails
I know there are other things going around with standard class which isn't visible in code, but how can I make my class to work?
Your version won't do anything because it has no implementation.
The real Random class has an external factory constructor (whose implementation lives elsewhere, one for the Dart VM/runtime, one for JavaScript) and that implementation instantiates an object that actually does something.
For customizing Random class, The external factory class must me declared somewhere else.
The main reason behind working of "Random" class is that its eternal factories are defined somewhere else, and being used in Random class.
While the reason behind not working of your "CustomRandom" class is that you are missing the implementation of your external factory "CustomRandom" anywhere.
Apparent solutions:
1) Keep class name CustomRandom but keep external factory name unchanged same as "Random" class.
2) Create own external factory and use here.
I'm writing test cases using XCTest framework provided by apple. I come up with situation where i want to mock local variables allocated inside the function like this below
-(void)myFunction{
A* a = [[A alloc] init];
}
from my testcase class i want to mock class A inside my function testMyFunction . Is there any way to do it without using OCMock.
If it's okay to create the instance first, then inject it using normal Dependency Injection techniques.
But if you need to ensure that the instance won't be created until it's needed, you have a few choices:
Inject a class, as #dasdom says. Then call its initializer when you need it.
Inject a block that acts as a Factory. Call it when you need it.
For more complex initialization: inject a Factory. I'd typically make this conform to a protocol, to make replacements clear.
You could inject the class to be used in the method into the system unter test. In the test you can use a different class.
I am following a View Based Class model to setup a Calabash testing framework for my app , i.e., each view has a class containing the requisite methods for that view.
But when I call calabash functions such as "wait_for()" it throws me an error:
undefined method `wait_for' for LoggedInPage:Class (NoMethodError)
I have already added these in my env.rb
require 'calabash-cucumber/wait_helpers'
require 'calabash-cucumber/operations'
World(Calabash::Cucumber::Operations)
World(Calabash::Cucumber::WaitHelpers)
The issue probably that the page object classes aren't being initialised in the same 'world' as cucumber is running in. Adding the files to env adds them and their methods to the world that cucumber is running. You have to pass that world into your page objects when they are created to give them access to those functions.
Have your page object classes inherit from calabashes page object bases - http://www.rubydoc.info/gems/calabash-cucumber/Calabash/IBase
and when you create a new instance of a page object pass in self.
class MyPage < Calabash::IBase
...
new_instance_of_page_object = MyPage.new(self)
In this specific case, inheriting from IBase will give you access to the functions you are talking about, but passing in self will mean you have access to any other things that you have added in your env file.
From a "good-design" perspective. Should I use the appDelegate class for all app-level common code? In other words, I have many things that many view controllers need to be able to do. That means it's common functionality, not specific to a single view controller. So the question is: Should I house these common methods in the appDelegate? Is that what it's for? Should I create another separate class?
Here are a few examples of the common functionality I speak of:
1) Play a common sound (such as error sound).
2) Show an alert message (such as an error message).
3) Method to validate input that should be of a specific type (decimal-numeric)
4) Update app-level data from a web service
Put all common functions to appDelegate class is not good idea.
1 & 2) You can create super class and all your view controller inherit it or use category.
3 & 4) You can create a normal function class to achieve. e.g. Your class name is Function and you have class method, to use it just simple call [Function validate:yourdata] return boolen value.
If it's data-related, then having a separate Model layer in your app makes the most sense to me. If it's code related specifically to how you like your view controllers to behave then a common super-class or even a UIViewController category sounds more like the right solution.
I see the app delegate as more about setting up the basic application structure (which might include connecting the Model and Controller layers) and dealing with its life cycle.
We have an MVC 3 Razor web project where we specify a custom base class for our views. In the InitializePage method of this base view class, we are doing some initialization and saving an object to the ViewBag. This information serves as sort of a "model" for our layout pages. One piece of information here a structured context menu that is rendered in the layout pages. The items on this menu can change, depending on the user that is logged into our site.
My question is how I can unit test this code that runs in the base view class. Since this code only runs when the view is rendered, do I have any choices other than mocking up a controller context under which to execute the view? I've seen some samples on the internet about doing that and it seems like it's more trouble than it's worth.
Any thoughts would be helpful. Thanks!
To me, the obvious solution would be to extract that code (or at least the bulk of it) into a method of another class. Then your View class should simply pass the appropriate values to that method, making its InitializePage method sufficiently simple that it has no need for unit testing. You can unit test the method independently of the View class.